public bool TryAddUnspentTxOutput(TxOutputKey txOutputKey, TxOutput txOutput) { CheckWriteTransaction(); using (SetSessionContext()) { try { using (var jetUpdate = this.jetSession.BeginUpdate(this.unspentTxOutputTableId, JET_prep.Insert)) { Api.SetColumns(this.jetSession, this.unspentTxOutputTableId, new BytesColumnValue { Columnid = this.txOutputKeyColumnId, Value = DbEncoder.EncodeTxOutputKey(txOutputKey) }, new BytesColumnValue { Columnid = this.txOutputBytesColumnId, Value = DataEncoder.EncodeTxOutput(txOutput) }); jetUpdate.Save(); } return(true); } catch (EsentKeyDuplicateException) { return(false); } } }
public bool ContainsUnspentTxOutput(TxOutputKey txOutputKey) { CheckTransaction(); using (SetSessionContext()) { Api.JetSetCurrentIndex(this.jetSession, this.unspentTxOutputTableId, "IX_TxOutputKey"); Api.MakeKey(this.jetSession, this.unspentTxOutputTableId, DbEncoder.EncodeTxOutputKey(txOutputKey), MakeKeyGrbit.NewKey); return(Api.TrySeek(this.jetSession, this.unspentTxOutputTableId, SeekGrbit.SeekEQ)); } }
public bool TryRemoveUnspentTxOutput(TxOutputKey txOutputKey) { CheckWriteTransaction(); using (SetSessionContext()) { Api.JetSetCurrentIndex(this.jetSession, this.unspentTxOutputTableId, "IX_TxOutputKey"); Api.MakeKey(this.jetSession, this.unspentTxOutputTableId, DbEncoder.EncodeTxOutputKey(txOutputKey), MakeKeyGrbit.NewKey); if (Api.TrySeek(this.jetSession, this.unspentTxOutputTableId, SeekGrbit.SeekEQ)) { Api.JetDelete(this.jetSession, this.unspentTxOutputTableId); return(true); } else { return(false); } } }
public bool TryGetUnspentTxOutput(TxOutputKey txOutputKey, out TxOutput txOutput) { CheckTransaction(); using (SetSessionContext()) { Api.JetSetCurrentIndex(this.jetSession, this.unspentTxOutputTableId, "IX_TxOutputKey"); Api.MakeKey(this.jetSession, this.unspentTxOutputTableId, DbEncoder.EncodeTxOutputKey(txOutputKey), MakeKeyGrbit.NewKey); if (Api.TrySeek(this.jetSession, this.unspentTxOutputTableId, SeekGrbit.SeekEQ)) { var txOutputBytesColumn = new BytesColumnValue { Columnid = this.txOutputBytesColumnId }; Api.RetrieveColumns(this.jetSession, this.unspentTxOutputTableId, txOutputBytesColumn); txOutput = DataDecoder.DecodeTxOutput(txOutputBytesColumn.Value); return(true); } txOutput = default(TxOutput); return(false); } }