public static byte[] EncodeRawTransaction(RawTransaction rawTransaction) { var values = asRlpValues(rawTransaction); var rlpList = new RlpList(values); return(RlpEncoder.Encode(rlpList)); }
public async Task CreateTransaction() { var chainTag = await _vechainClient.GetChainTag(); var blockref = "0x001a7d4448f0948b"; // await _vechainClient.GetLatestBlockRef(); var trans = RawTransaction.CreateUnsigned(chainTag, blockref, new[] { new RawClause("0xd3ae78222beadb038203be21ed5ce7c9b1bff602", "1", "", false) }, "12345678", 720, 0, 21000, ""); var rlpTransaction = new RlpTransaction(trans).AsRlpValues(); var asHexString = RlpEncoder.Encode(rlpTransaction); var rawTransaction = asHexString.ByteArrayToString(StringType.Hex | StringType.ZeroLowerX); // 0x44C3e1Ce754129Eb74522E3CA5695B7Cfa6d2B19 var privateKey = new BigInteger("0xdce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65".HexStringToByteArray()); var publicKey = ECDSASign.PublicKeyFromPrivate(privateKey); var customKey = new ECKeyPair(privateKey, publicKey); var result = trans.Sign(customKey).CalculateTxId(new Address(customKey.GetHexAddress())).Transfer(_vechainClient); }
// 노드를 RLP로 인코딩한다. internal TrieNode EncodeRLP() { if (Parsed || Dirty) { // 브랜치 노드 인코딩 if (Type == NodeType.FullNode) { var encoder = new RlpEncoder(); for (int i = 0; i < 16; i++) { encoder.Add(chidrens[i]?.Hash); } encoder.Add(value); rlp = encoder.Encode(); } else if (Type == NodeType.ShortNode) { // 익스텐션 노드 인코딩 rlp = new RlpEncoder(Key, Next.Hash).Encode(); } else if (Type == NodeType.ValueNode) { // 리프 노드 인코딩 rlp = new RlpEncoder(Key, Value).Encode(); } else { throw new Exception("can't encode unknown node type"); } } return(this); }
public void RLPHexParser() { // based on https://github.com/vechain/thor/blob/d9f618b4974733e04949f7b9424001f5bd572baa/tx/transaction_test.go#L20 string to = "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"; var realTransaction = new RawTransaction { chainTag = 1, blockRef = "00000000aabbccdd", expiration = 32, clauses = new[] { new RawClause(to, "10000", "0x000000606060", false), new RawClause(to, "20000", "0x000000606060", false) }, gasPriceCoef = 128, gas = 21000, dependsOn = null, nonce = "12345678" }; var rlpTransaction = new RlpTransaction(realTransaction).AsRlpValues(); var vetEncoded = RlpEncoder.Encode(rlpTransaction); var out1 = vetEncoded.ByteArrayToString(StringType.Hex | StringType.ZeroLowerX); Assert.Equal("0xf8550184aabbccdd20f840df947567d83b7b8d80addcb281a71d54fc7b3364ffed82271086000000606060df947567d83b7b8d80addcb281a71d54fc7b3364ffed824e208600000060606081808252088083bc614ec080", out1); var vethash = Hash.HashBlake2B(vetEncoded); // Should be 2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478 var vethashReadable = vethash.ByteArrayToString(StringType.Hex | StringType.ZeroLowerX); Assert.Equal("0x2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478", vethashReadable); }
/// <summary> /// Sign the transaction by RLP encoding it and calculating the signature of the resulting byte[]. /// </summary> /// <param name="transaction">The transaction that will be signed.</param> /// <param name="key">The key with which the transaction will be signed.</param> /// <returns>The signed transaction</returns> public static RawTransaction Sign(this RawTransaction transaction, ECKeyPair key) { var rlp = RlpEncoder.Encode(new RlpTransaction(transaction).AsRlpValues()); SignatureData signatureData = ECDSASign.SignMessage(rlp, key, true); transaction.signature = signatureData.ToByteArray(); return(transaction); }
// new empty branch node public TrieNode(ITrie trie) { this.trie = trie; rlp = RlpEncoder.New(17).Encode(); Type = NodeType.FullNode; Dirty = true; DecodeRLP(); }
public void DecoderTest() { string hexRaw = "0xf83d81c7860881eec535498202d0e1e094000000002beadb038203be21ed5ce7c9b1bff60289056bc75e2d63100000808082520880884773cc184328eb3ec0"; var rlpList = RlpDecoder.Decode(hexRaw.HexStringToByteArray()); // The list should only have 1 element Assert.Single(rlpList); byte[] encodedinner = RlpEncoder.Encode(rlpList[0]); string hexEncodedinner = encodedinner.ByteArrayToString(StringType.Hex | StringType.ZeroLowerX); Assert.Equal(hexRaw, hexEncodedinner); }
private byte[] ToRlp() { return(RlpEncoder.EncodeList(Order, Seller, ItemCode, ItemName, Coin.ToBeryl(Price))); }
private byte[] ToRlp() { return(RlpEncoder.EncodeList(Id, PassHash, RegisterDate)); }
/// <summary> /// RLP encode the transaction and turn it into a byte[] /// </summary> /// <param name="rawTransaction">The transaction that is to be encoded</param> /// <returns>The encoded transaction</returns> public static byte[] Encode(this RawTransaction rawTransaction) { return(RlpEncoder.Encode(new RlpTransaction(rawTransaction).AsRlpValues())); }
private byte[] ToRlp() { return(RlpEncoder.EncodeList(ToArray())); }
private byte[] ToRlp() { return(RlpEncoder.EncodeList(Code, Name, Price)); }
protected virtual H256 ToTxid() { return(RlpEncoder.EncodeList(chain, version, to, value, gas, nonce, data, extra, seal).Hash256()); }
protected virtual byte[] ToRlp() { return(RlpEncoder.EncodeList(chain, version, to, value, gas, nonce, data, extra, seal, metadata)); }