项目作者: KingHodor

项目描述 :
C Ethereum RLP library
高级语言: C
项目地址: git://github.com/KingHodor/Ethereum-RLP.git
创建时间: 2018-04-18T06:00:06Z
项目社区:https://github.com/KingHodor/Ethereum-RLP

开源协议:

下载


Ethereum RLP C library

RLP is the serialization format that Ethereum uses to serialize objects to raw bytes.

Read more in the documentation on ReadTheDocs.

Example ( Assemble a transaction from its components)

  1. int wallet_ethereum_assemble_tx(EthereumSignTx *msg, EthereumSig *tx, uint64_t *rawTx) {
  2. EncodeEthereumSignTx new_msg;
  3. EncodeEthereumTxRequest new_tx;
  4. memset(&new_msg, 0, sizeof(new_msg));
  5. memset(&new_tx, 0, sizeof(new_tx));
  6. wallet_encode_element(msg->nonce.bytes, msg->nonce.size,
  7. new_msg.nonce.bytes, &(new_msg.nonce.size), false);
  8. wallet_encode_element(msg->gas_price.bytes, msg->gas_price.size,
  9. new_msg.gas_price.bytes, &(new_msg.gas_price.size), false);
  10. wallet_encode_element(msg->gas_limit.bytes, msg->gas_limit.size,
  11. new_msg.gas_limit.bytes, &(new_msg.gas_limit.size), false);
  12. wallet_encode_element(msg->to.bytes, msg->to.size, new_msg.to.bytes,
  13. &(new_msg.to.size), false);
  14. wallet_encode_element(msg->value.bytes, msg->value.size,
  15. new_msg.value.bytes, &(new_msg.value.size), false);
  16. wallet_encode_element(msg->data_initial_chunk.bytes,
  17. msg->data_initial_chunk.size, new_msg.data_initial_chunk.bytes,
  18. &(new_msg.data_initial_chunk.size), false);
  19. wallet_encode_int(tx->signature_v, &(new_tx.signature_v));
  20. wallet_encode_element(tx->signature_r.bytes, tx->signature_r.size,
  21. new_tx.signature_r.bytes, &(new_tx.signature_r.size), true);
  22. wallet_encode_element(tx->signature_s.bytes, tx->signature_s.size,
  23. new_tx.signature_s.bytes, &(new_tx.signature_s.size), true);
  24. int length = wallet_encode_list(&new_msg, &new_tx, rawTx);
  25. return length;
  26. }
  1. void assembleTx() {
  2. static char rawTx[256];
  3. EthereumSignTx tx;
  4. EthereumSig signature;
  5. uint64_t raw_tx_bytes[24];
  6. const char *nonce = "00";
  7. const char *gas_price = "4a817c800";
  8. const char *gas_limit = "5208";
  9. const char *to = "e0defb92145fef3c3a945637705fafd3aa74a241";
  10. const char *value = "de0b6b3a7640000";
  11. const char *data = "00";
  12. const char *r = "09ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9c";
  13. const char *s = "440ffd775ce91a833ab410777204d5341a6f9fa91216a6f3ee2c051fea6a0428";
  14. uint32_t v = 27;
  15. tx.nonce.size = size_of_bytes(strlen(nonce));
  16. hex2byte_arr(nonce, strlen(nonce), tx.nonce.bytes, tx.nonce.size);
  17. tx.gas_price.size = size_of_bytes(strlen(gas_price));
  18. hex2byte_arr(gas_price, strlen(gas_price), tx.gas_price.bytes, tx.gas_price.size);
  19. tx.gas_limit.size = size_of_bytes(strlen(gas_limit));
  20. hex2byte_arr(gas_limit, strlen(gas_limit), tx.gas_limit.bytes, tx.gas_limit.size);
  21. tx.to.size = size_of_bytes(strlen(to));
  22. hex2byte_arr(to, strlen(to), tx.to.bytes, tx.to.size);
  23. tx.value.size = size_of_bytes(strlen(value));
  24. hex2byte_arr(value, strlen(value), tx.value.bytes, tx.value.size);
  25. tx.data_initial_chunk.size = size_of_bytes(strlen(data));
  26. hex2byte_arr(data, strlen(data), tx.data_initial_chunk.bytes,
  27. tx.data_initial_chunk.size);
  28. signature.signature_v = 27;
  29. signature.signature_r.size = size_of_bytes(strlen(r));
  30. hex2byte_arr(r, strlen(r), signature.signature_r.bytes, signature.signature_r.size);
  31. signature.signature_s.size = size_of_bytes(strlen(s));
  32. hex2byte_arr(s, strlen(s), signature.signature_s.bytes, signature.signature_s.size);
  33. int length = wallet_ethereum_assemble_tx(&tx, &signature, raw_tx_bytes);
  34. int8_to_char((uint8_t *) raw_tx_bytes, length, rawTx);
  35. printf("raw tx: %s", rawTx);
  36. }

Output:

  1. raw transaction: f86c008504a817c80082520894e0defb92145fef3c3a945637705fafd3aa74a209880de0b6b3a7640000001ba009ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9ca0440ffd775ce91a833ab410777204d5341a6f9fa91216a6f3ee2c051fea6a0428

Getting help

Please contact sfa.alptekin@gmail.com