public bool TryAddUnspentTx(UnspentTx unspentTx) { CheckWriteTransaction(); using (SetSessionContext()) { try { using (var jetUpdate = this.jetSession.BeginUpdate(this.unspentTxTableId, JET_prep.Insert)) { Api.SetColumns(this.jetSession, this.unspentTxTableId, new BytesColumnValue { Columnid = this.txHashColumnId, Value = DbEncoder.EncodeUInt256(unspentTx.TxHash) }, new Int32ColumnValue { Columnid = this.blockIndexColumnId, Value = unspentTx.BlockIndex }, new Int32ColumnValue { Columnid = this.txIndexColumnId, Value = unspentTx.TxIndex }, new UInt32ColumnValue { Columnid = this.txVersionColumnId, Value = unspentTx.TxVersion }, new BoolColumnValue { Columnid = this.isCoinbaseColumnId, Value = unspentTx.IsCoinbase }, new BytesColumnValue { Columnid = this.outputStatesColumnId, Value = DataEncoder.EncodeOutputStates(unspentTx.OutputStates) }); jetUpdate.Save(); } return(true); } catch (EsentKeyDuplicateException) { return(false); } } }
public bool TryUpdateUnspentTx(UnspentTx unspentTx) { CheckWriteTransaction(); using (SetSessionContext()) { Api.JetSetCurrentIndex(this.jetSession, this.unspentTxTableId, "IX_TxHash"); Api.MakeKey(this.jetSession, this.unspentTxTableId, DbEncoder.EncodeUInt256(unspentTx.TxHash), MakeKeyGrbit.NewKey); if (Api.TrySeek(this.jetSession, this.unspentTxTableId, SeekGrbit.SeekEQ)) { using (var jetUpdate = this.jetSession.BeginUpdate(this.unspentTxTableId, JET_prep.Replace)) { Api.SetColumn(this.jetSession, this.unspentTxTableId, this.outputStatesColumnId, DataEncoder.EncodeOutputStates(unspentTx.OutputStates)); jetUpdate.Save(); } return(true); } else { return(false); } } }
public void AddTransaction(UInt256 txHash, UnspentTx unspentTx) { Api.JetBeginTransaction(this.jetSession); try { Api.JetPrepareUpdate(this.jetSession, this.unspentTxTableId, JET_prep.Insert); try { Api.SetColumn(this.jetSession, this.unspentTxTableId, this.txHashColumnId, txHash.ToByteArray()); Api.SetColumn(this.jetSession, this.unspentTxTableId, this.confirmedBlockHashColumnId, unspentTx.ConfirmedBlockHash.ToByteArray()); Api.SetColumn(this.jetSession, this.unspentTxTableId, this.outputStatesColumnId, DataEncoder.EncodeOutputStates(unspentTx.OutputStates)); Api.JetUpdate(this.jetSession, this.unspentTxTableId); Api.JetCommitTransaction(this.jetSession, CommitTransactionGrbit.LazyFlush); this.unspentTxCount++; } catch (Exception) { Api.JetPrepareUpdate(this.jetSession, this.unspentTxTableId, JET_prep.Cancel); throw; } } catch (Exception) { Api.JetRollback(this.jetSession, RollbackTransactionGrbit.None); throw; } }
public void UpdateTransaction(UInt256 txHash, UnspentTx unspentTx) { Api.JetBeginTransaction(this.jetSession); try { //Api.JetSetCurrentIndex(this.jetSession, this.unspentTxTableId, "IX_TxHash"); Api.MakeKey(this.jetSession, this.unspentTxTableId, txHash.ToByteArray(), MakeKeyGrbit.NewKey); if (!Api.TrySeek(this.jetSession, this.unspentTxTableId, SeekGrbit.SeekEQ)) { throw new KeyNotFoundException(); } Api.JetPrepareUpdate(this.jetSession, this.unspentTxTableId, JET_prep.Replace); try { Api.SetColumn(this.jetSession, this.unspentTxTableId, this.outputStatesColumnId, DataEncoder.EncodeOutputStates(unspentTx.OutputStates)); Api.JetUpdate(this.jetSession, this.unspentTxTableId); Api.JetCommitTransaction(this.jetSession, CommitTransactionGrbit.LazyFlush); } catch (Exception) { Api.JetPrepareUpdate(this.jetSession, this.unspentTxTableId, JET_prep.Cancel); throw; } } catch (Exception) { Api.JetRollback(this.jetSession, RollbackTransactionGrbit.None); throw; } }
public bool TryAddUnspentTx(UnspentTx unspentTx) { if (!this.inTransaction) { throw new InvalidOperationException(); } try { using (var jetUpdate = this.jetSession.BeginUpdate(this.unspentTxTableId, JET_prep.Insert)) { Api.SetColumn(this.jetSession, this.unspentTxTableId, this.txHashColumnId, DbEncoder.EncodeUInt256(unspentTx.TxHash)); Api.SetColumn(this.jetSession, this.unspentTxTableId, this.blockIndexColumnId, unspentTx.BlockIndex); Api.SetColumn(this.jetSession, this.unspentTxTableId, this.txIndexColumnId, unspentTx.TxIndex); Api.SetColumn(this.jetSession, this.unspentTxTableId, this.outputStatesColumnId, DataEncoder.EncodeOutputStates(unspentTx.OutputStates)); jetUpdate.Save(); // increase unspent tx count Api.EscrowUpdate(this.jetSession, this.globalsTableId, this.unspentTxCountColumnId, +1); return(true); } } catch (EsentKeyDuplicateException) { return(false); } }