static EndorsementContent UnforgeEndorsement(ForgedReader reader) { return(new EndorsementContent { Level = reader.ReadInt32() }); }
static Script UnforgeScript(ForgedReader reader) { return(new Script { Code = (MichelineArray)reader.ReadEnumerableSingle(UnforgeMicheline), Storage = reader.ReadEnumerableSingle(UnforgeMicheline) }); }
static SeedNonceRevelationContent UnforgeSeedNonceRevelaion(ForgedReader reader) { return(new SeedNonceRevelationContent { Level = reader.ReadInt32(), Nonce = Hex.Convert(reader.ReadBytes(Lengths.nce.Decoded)) }); }
static DoublePreendorsementContent UnforgeDoublePreendorsement(ForgedReader reader) { return(new DoublePreendorsementContent { Op1 = reader.ReadEnumerableSingle(UnforgeInlinedPreendorsement), Op2 = reader.ReadEnumerableSingle(UnforgeInlinedPreendorsement) }); }
static DoubleBakingContent UnforgeDoubleBaking(ForgedReader reader) { return(new DoubleBakingContent { BlockHeader1 = reader.ReadEnumerableSingle(UnforgeBlockHeader), BlockHeader2 = reader.ReadEnumerableSingle(UnforgeBlockHeader) }); }
static ActivationContent UnforgeActivation(ForgedReader reader) { return(new ActivationContent { Address = reader.ReadTz1Address(), Secret = Hex.Convert(reader.ReadBytes(20)) }); }
static InlinedPreendorsement UnforgeInlinedPreendorsement(ForgedReader reader) { return(new InlinedPreendorsement { Branch = reader.ReadBase58(Lengths.B.Decoded, Prefix.B), Operations = (PreendorsementContent)UnforgeOperation(reader), Signature = reader.ReadBase58(Lengths.sig.Decoded, Prefix.sig) }); }
static ProposalsContent UnforgeProposals(ForgedReader reader) { return(new ProposalsContent { Source = reader.ReadTzAddress(), Period = reader.ReadInt32(), Proposals = reader.ReadEnumerable(r => r.ReadBase58(Lengths.P.Decoded, Prefix.P)).ToList() }); }
static BallotContent UnforgeBallot(ForgedReader reader) { return(new BallotContent { Source = reader.ReadTzAddress(), Period = reader.ReadInt32(), Proposal = reader.ReadBase58(Lengths.P.Decoded, Prefix.P), Ballot = (Ballot)reader.ReadByte() }); }
static VdfRevelationContent UnforgeVdfRevelaion(ForgedReader reader) { return(new VdfRevelationContent { Solution = new(2) { Hex.Convert(reader.ReadBytes(100)), Hex.Convert(reader.ReadBytes(100)) } });
static PreendorsementContent UnforgePreendorsement(ForgedReader reader) { return(new PreendorsementContent { Slot = reader.ReadInt32(2), Level = reader.ReadInt32(), Round = reader.ReadInt32(), PayloadHash = reader.ReadBase58(32, Prefix.vh) }); }
static OperationContent UnforgeOperation(ForgedReader reader) { var operation = (int)reader.ReadUBigInt(); switch ((OperationTag)operation) { case OperationTag.Endorsement: return(UnforgeEndorsement(reader)); case OperationTag.Preendorsement: return(UnforgePreendorsement(reader)); case OperationTag.Ballot: return(UnforgeBallot(reader)); case OperationTag.Proposals: return(UnforgeProposals(reader)); case OperationTag.Activation: return(UnforgeActivation(reader)); case OperationTag.DoubleBaking: return(UnforgeDoubleBaking(reader)); case OperationTag.DoubleEndorsement: return(UnforgeDoubleEndorsement(reader)); case OperationTag.DoublePreendorsement: return(UnforgeDoublePreendorsement(reader)); case OperationTag.SeedNonceRevelation: return(UnforgeSeedNonceRevelaion(reader)); case OperationTag.Delegation: return(UnforgeDelegation(reader)); case OperationTag.Origination: return(UnforgeOrigination(reader)); case OperationTag.Transaction: return(UnforgeTransaction(reader)); case OperationTag.Reveal: return(UnforgeReveal(reader)); case OperationTag.RegisterConstant: return(UnforgeRegisterConstant(reader)); case OperationTag.SetDepositsLimit: return(UnforgeSetDepositsLimit(reader)); default: throw new ArgumentException($"Invalid operation: {operation}"); } }
public static IMicheline UnforgeMicheline(ForgedReader reader) { var micheline = reader.ReadMicheline(); if (!reader.EndOfStream) { throw new ArgumentException($"Did not reach EOS (position: {reader.StreamPosition})"); } return(micheline); }
static Parameters UnforgeParameters(ForgedReader reader) { return(UnforgeConditional(reader, () => { return new Parameters { Entrypoint = UnforgeEntrypoint(reader), Value = reader.ReadEnumerableSingle(UnforgeMicheline) }; })); }
static DelegationContent UnforgeDelegation(ForgedReader reader) { return(new DelegationContent { Source = reader.ReadTzAddress(), Fee = (long)reader.ReadUBigInt(), Counter = (int)reader.ReadUBigInt(), GasLimit = (int)reader.ReadUBigInt(), StorageLimit = (int)reader.ReadUBigInt(), Delegate = UnforgeDelegate(reader) }); }
static RevealContent UnforgeReveal(ForgedReader reader) { return(new RevealContent { Source = reader.ReadTzAddress(), Fee = (long)reader.ReadUBigInt(), Counter = (int)reader.ReadUBigInt(), GasLimit = (int)reader.ReadUBigInt(), StorageLimit = (int)reader.ReadUBigInt(), PublicKey = reader.ReadPublicKey() }); }
static RegisterConstantContent UnforgeRegisterConstant(ForgedReader reader) { return(new RegisterConstantContent { Source = reader.ReadTzAddress(), Fee = (long)reader.ReadUBigInt(), Counter = (int)reader.ReadUBigInt(), GasLimit = (int)reader.ReadUBigInt(), StorageLimit = (int)reader.ReadUBigInt(), Value = reader.ReadEnumerableSingle(UnforgeMicheline) }); }
static SetDepositsLimitContent UnforgeSetDepositsLimit(ForgedReader reader) { return(new SetDepositsLimitContent { Source = reader.ReadTzAddress(), Fee = (long)reader.ReadUBigInt(), Counter = (int)reader.ReadUBigInt(), GasLimit = (int)reader.ReadUBigInt(), StorageLimit = (int)reader.ReadUBigInt(), Limit = reader.ReadBool() ? reader.ReadUBigInt() : null }); }
static TransactionContent UnforgeTransaction(ForgedReader reader) { return(new TransactionContent { Source = reader.ReadTzAddress(), Fee = (long)reader.ReadUBigInt(), Counter = (int)reader.ReadUBigInt(), GasLimit = (int)reader.ReadUBigInt(), StorageLimit = (int)reader.ReadUBigInt(), Amount = (long)reader.ReadUBigInt(), Destination = reader.ReadAddress(), Parameters = UnforgeParameters(reader) }); }
public Task <(string, IEnumerable <OperationContent>)> UnforgeOperationAsync(byte[] bytes) { using (var reader = new ForgedReader(bytes)) { var branch = reader.ReadBase58(Lengths.B.Decoded, Prefix.B); var content = new List <OperationContent>(); while (!reader.EndOfStream) { content.Add(UnforgeOperation(reader)); } return(Task.FromResult((branch, (IEnumerable <OperationContent>)content))); } }
public MichelineArray ReadMichelineArray() { var arrayData = ReadArray(); var res = new MichelineArray(); using (var arr = new ForgedReader(arrayData)) { while (!arr.EndOfStream) { res.Add(arr.ReadMicheline()); } } return(res); }
public IEnumerable <T> ReadEnumerable <T>(Func <ForgedReader, T> readData) { if (!EndOfStream) { var arrLen = ReadInt32(); var arrData = ReadBytes(arrLen); using (var reader = new ForgedReader(arrData)) { while (!reader.EndOfStream) { yield return(readData(reader)); } } } yield break; }
static BlockHeader UnforgeBlockHeader(ForgedReader reader) { return(new BlockHeader { Level = reader.ReadInt32(), Proto = reader.ReadInt32(1), Predecessor = reader.ReadBase58(Lengths.B.Decoded, Prefix.B), Timestamp = DateTimeExtension.FromUnixTime(reader.ReadInt64()), ValidationPass = reader.ReadInt32(1), OperationsHash = reader.ReadBase58(Lengths.LLo.Decoded, Prefix.LLo), Fitness = reader.ReadEnumerable(r => r.ReadHexString()).ToList(), Context = reader.ReadBase58(Lengths.Co.Decoded, Prefix.Co), Priority = reader.ReadInt32(2), ProofOfWorkNonce = Hex.Convert(reader.ReadBytes(8)), SeedNonceHash = UnforgeSeedNonce(reader), Signature = reader.ReadBase58(Lengths.sig.Decoded, Prefix.sig), }); }
public T ReadEnumerableSingle <T>(Func <ForgedReader, T> readData) { if (!EndOfStream) { var arrLen = ReadInt32(); var arrData = ReadBytes(arrLen); using (var reader = new ForgedReader(arrData)) { var result = readData(reader); if (!reader.EndOfStream) { throw new InvalidOperationException("Expected end of stream but not reached"); } return(result); } } return(default(T)); }
static string UnforgeEntrypoint(ForgedReader reader) { var ep = reader.ReadInt32(1); switch (ep) { case 0: return("default"); case 1: return("root"); case 2: return("do"); case 3: return("set_delegate"); case 4: return("remove_delegate"); case 255: return(reader.ReadString(1)); default: throw new ArgumentException($"Unrecognized endpoint type {ep}"); } }
static OperationContent UnforgeOperation(ForgedReader reader) { var operation = (OperationTag)reader.ReadByte(); switch (operation) { case OperationTag.Endorsement: return(UnforgeEndorsement(reader)); case OperationTag.Preendorsement: return(UnforgePreendorsement(reader)); case OperationTag.Ballot: return(UnforgeBallot(reader)); case OperationTag.Proposals: return(UnforgeProposals(reader)); case OperationTag.Activation: return(UnforgeActivation(reader)); case OperationTag.DoubleBaking: return(UnforgeDoubleBaking(reader)); case OperationTag.DoubleEndorsement: return(UnforgeDoubleEndorsement(reader)); case OperationTag.DoublePreendorsement: return(UnforgeDoublePreendorsement(reader)); case OperationTag.SeedNonceRevelation: return(UnforgeSeedNonceRevelaion(reader)); case OperationTag.VdfRevelation: return(UnforgeVdfRevelaion(reader)); case OperationTag.Delegation: return(UnforgeDelegation(reader)); case OperationTag.Origination: return(UnforgeOrigination(reader)); case OperationTag.Transaction: return(UnforgeTransaction(reader)); case OperationTag.Reveal: return(UnforgeReveal(reader)); case OperationTag.RegisterConstant: return(UnforgeRegisterConstant(reader)); case OperationTag.SetDepositsLimit: return(UnforgeSetDepositsLimit(reader)); case OperationTag.IncreasePaidStorage: return(UnforgeIncreasePaidStorage(reader)); case OperationTag.FailingNoop: return(UnforgeFailingNoop(reader)); case OperationTag.TransferTicket: return(UnforgeTransferTicket(reader)); case OperationTag.TxRollupCommit: return(UnforgeTxRollupCommit(reader)); case OperationTag.TxRollupDispatchTickets: return(UnforgeTxRollupDispatchTickets(reader)); case OperationTag.TxRollupFinalizeCommitment: return(UnforgeTxRollupFinalizeCommitment(reader)); case OperationTag.TxRollupOrigination: return(UnforgeTxRollupOrigination(reader)); case OperationTag.TxRollupRejection: return(UnforgeTxRollupRejection(reader)); case OperationTag.TxRollupRemoveCommitment: return(UnforgeTxRollupRemoveCommitment(reader)); case OperationTag.TxRollupReturnBond: return(UnforgeTxRollupReturnBond(reader)); case OperationTag.TxRollupSubmitBatch: return(UnforgeTxRollupSubmitBatch(reader)); default: throw new ArgumentException($"Invalid operation: {operation}"); } }
static string UnforgeSeedNonce(ForgedReader reader) { return(UnforgeConditional(reader, () => reader.ReadBase58(Lengths.nce.Decoded, Prefix.nce))); }
static string UnforgeDelegate(ForgedReader reader) { return(UnforgeConditional(reader, () => reader.ReadTzAddress())); }
static T UnforgeConditional <T>(ForgedReader reader, Func <T> tb, Func <T> fb = null) where T : class { return(reader.ReadBool() ? tb() : fb?.Invoke()); }