public MerkleTreePruningCursor(UInt256 blockHash, LightningTransaction txn, LightningDatabase db, LightningCursor cursor) { this.blockHash = blockHash; this.db = db; this.txn = txn; this.cursor = cursor; }
public static void Put <TKey, TValue>(this LightningCursor cur, TKey key, TValue value, PutOptions options = PutOptions.None) { var keyBytes = cur.ToBytes(key); var valueBytes = cur.ToBytes(value); cur.Put(keyBytes, valueBytes, options); }
public static IEnumerable <ValueTuple <MDBValue, MDBValue> > AsEnumerable(this LightningCursor cursor) { while (cursor.Next() == MDBResultCode.Success) { var(resultCode, key, value) = cursor.GetCurrent(); resultCode.ThrowOnError(); yield return(key, value); } }
public static KeyValuePair <TKey, TValue> GetCurrent <TKey, TValue>(this LightningCursor cursor) { var pair = cursor.GetCurrent(); var key = cursor.Database.FromBytes <TKey>(pair.Key); var value = cursor.Database.FromBytes <TValue>(pair.Value); return(new KeyValuePair <TKey, TValue>(key, value)); }
private static bool CursorMove <TKey, TValue>(LightningCursor cur, Func <KeyValuePair <byte[], byte[]>?> mover, out KeyValuePair <TKey, TValue> pair) { var op = CursorMoveBy(cur, mover); if (!op.PairExists) { pair = default(KeyValuePair <TKey, TValue>); return(false); } else { pair = op.Pair <TKey, TValue>(); return(true); } }
public CursorGetByOperation(LightningCursor cur, KeyValuePair <byte[], byte[]>?pair) { _cur = cur; _pair = pair; }
public static void Delete(this LightningCursor cur, bool removeAllDuplicateData = true) { cur.Delete( removeAllDuplicateData ? CursorDeleteOption.NoDuplicateData : CursorDeleteOption.None); }
internal static T FromBytes <T>(this LightningCursor cur, byte[] bytes) { return(cur.Database.FromBytes <T>(bytes)); }
internal static byte[] ToBytes <T>(this LightningCursor cur, T instance) { return(cur.Database.ToBytes(instance)); }
public static CursorGetByOperation MoveNextDuplicateBy(this LightningCursor cur) { return(CursorMoveBy(cur, cur.MoveNextDuplicate)); }
private static CursorGetByOperation CursorMoveBy(LightningCursor cur, Func <KeyValuePair <byte[], byte[]>?> mover) { return(new CursorGetByOperation(cur, mover.Invoke())); }
public static bool GetCurrent <TKey, TValue>(this LightningCursor cur, out KeyValuePair <TKey, TValue> pair) { return(CursorMove <TKey, TValue>(cur, cur.GetCurrent, out pair)); }
public static CursorGetByOperation GetCurrentBy(this LightningCursor cur) { return(CursorMoveBy(cur, cur.GetCurrent)); }
public static bool MoveToLast <TKey, TValue>(this LightningCursor cur, out KeyValuePair <TKey, TValue> pair) { return(CursorMove <TKey, TValue>(cur, cur.MoveToLast, out pair)); }
public static CursorGetByOperation MoveToLastBy(this LightningCursor cur) { return(CursorMoveBy(cur, cur.MoveToLast)); }
private static long ReadInternal(IEnumerable<uint> ids, PerfTracker perfTracker, LightningEnvironment env, LightningDatabase db) { using (var tx = env.BeginTransaction(LightningDB.TransactionBeginFlags.ReadOnly)) using (var cursor = new LightningCursor(db, tx)) { long v = 0; foreach (var id in ids) { var value = cursor.MoveTo(Encoding.UTF8.GetBytes(id.ToString("0000000000000000"))); v += value.Value.Length; //Debug.Assert(value != null); } return v; } }
public static bool MoveNextDuplicate <TKey, TValue>(this LightningCursor cur, out KeyValuePair <TKey, TValue> pair) { return(CursorMove <TKey, TValue>(cur, cur.MoveNextDuplicate, out pair)); }