public static Transaction Decode(byte[] raw, bool unsigned = true) { if (unsigned) { return(RlpCode.Decode(Transaction.UnsignedRlpDefinition(), raw, typeof(Transaction))); } else { return(RlpCode.Decode(Transaction.SignedRlpDefinition(), raw, typeof(Transaction))); } }
public byte[] SigningHash(string delegateFor = "") { byte[] encode = RlpCode.Encode(Transaction.UnsignedRlpDefinition(), this.Body); byte[] hash = Blake2b.CalculateHash(encode); if (delegateFor.Length != 0) { if (SimpleWallet.IsValidAddress(delegateFor)) { MemoryStream stream = new MemoryStream(); stream.Append(hash); stream.Append(delegateFor.ToBytes()); return(Blake2b.CalculateHash(stream.ToArray())); } else { throw new ArgumentException("delegateFor expected address"); } } return(hash); }
public byte[] Encode() { this.TrimReserved(); if (this.Signature != null && this.Signature.Length != 0) { var transaction = new { ChainTag = this.Body.ChainTag, BlockRef = this.Body.BlockRef, Expiration = this.Body.Expiration, Clauses = this.Body.Clauses, GasPriceCoef = this.Body.GasPriceCoef, Gas = this.Body.Gas, DependsOn = this.Body.DependsOn, Nonce = this.Body.Nonce, Reserved = this.Body.Reserved, Signature = this.Signature }; return(RlpCode.Encode(Transaction.SignedRlpDefinition(), transaction)); } else { return(RlpCode.Encode(Transaction.UnsignedRlpDefinition(), this.Body)); } }