-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.c
More file actions
90 lines (73 loc) · 3.63 KB
/
Copy pathmain.c
File metadata and controls
90 lines (73 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright (c) 2016-2018 . All Rights Reserved.
*/
#include <stdio.h>
#include <string.h>
#include "utils.h"
#include "RLP.h"
int wallet_ethereum_assemble_tx(EthereumSignTx *msg, EthereumSig *tx, uint64_t *rawTx) {
EncodeEthereumSignTx new_msg;
EncodeEthereumTxRequest new_tx;
memset(&new_msg, 0, sizeof(new_msg));
memset(&new_tx, 0, sizeof(new_tx));
wallet_encode_element(msg->nonce.bytes, msg->nonce.size,
new_msg.nonce.bytes, &(new_msg.nonce.size), false);
wallet_encode_element(msg->gas_price.bytes, msg->gas_price.size,
new_msg.gas_price.bytes, &(new_msg.gas_price.size), false);
wallet_encode_element(msg->gas_limit.bytes, msg->gas_limit.size,
new_msg.gas_limit.bytes, &(new_msg.gas_limit.size), false);
wallet_encode_element(msg->to.bytes, msg->to.size, new_msg.to.bytes,
&(new_msg.to.size), false);
wallet_encode_element(msg->value.bytes, msg->value.size,
new_msg.value.bytes, &(new_msg.value.size), false);
wallet_encode_element(msg->data_initial_chunk.bytes,
msg->data_initial_chunk.size, new_msg.data_initial_chunk.bytes,
&(new_msg.data_initial_chunk.size), false);
wallet_encode_int(tx->signature_v, &(new_tx.signature_v));
wallet_encode_element(tx->signature_r.bytes, tx->signature_r.size,
new_tx.signature_r.bytes, &(new_tx.signature_r.size), true);
wallet_encode_element(tx->signature_s.bytes, tx->signature_s.size,
new_tx.signature_s.bytes, &(new_tx.signature_s.size), true);
int length = wallet_encode_list(&new_msg, &new_tx, rawTx);
return length;
}
void assembleTx() {
static char rawTx[256];
EthereumSignTx tx;
EthereumSig signature;
uint64_t raw_tx_bytes[24];
const char *nonce = "00";
const char *gas_price = "4a817c800";
const char *gas_limit = "5208";
const char *to = "e0defb92145fef3c3a945637705fafd3aa74a241";
const char *value = "de0b6b3a7640000";
const char *data = "00";
const char *r = "09ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9c";
const char *s = "440ffd775ce91a833ab410777204d5341a6f9fa91216a6f3ee2c051fea6a0428";
uint32_t v = 27;
tx.nonce.size = size_of_bytes(strlen(nonce));
hex2byte_arr(nonce, strlen(nonce), tx.nonce.bytes, tx.nonce.size);
tx.gas_price.size = size_of_bytes(strlen(gas_price));
hex2byte_arr(gas_price, strlen(gas_price), tx.gas_price.bytes, tx.gas_price.size);
tx.gas_limit.size = size_of_bytes(strlen(gas_limit));
hex2byte_arr(gas_limit, strlen(gas_limit), tx.gas_limit.bytes, tx.gas_limit.size);
tx.to.size = size_of_bytes(strlen(to));
hex2byte_arr(to, strlen(to), tx.to.bytes, tx.to.size);
tx.value.size = size_of_bytes(strlen(value));
hex2byte_arr(value, strlen(value), tx.value.bytes, tx.value.size);
tx.data_initial_chunk.size = size_of_bytes(strlen(data));
hex2byte_arr(data, strlen(data), tx.data_initial_chunk.bytes,
tx.data_initial_chunk.size);
signature.signature_v = 27;
signature.signature_r.size = size_of_bytes(strlen(r));
hex2byte_arr(r, strlen(r), signature.signature_r.bytes, signature.signature_r.size);
signature.signature_s.size = size_of_bytes(strlen(s));
hex2byte_arr(s, strlen(s), signature.signature_s.bytes, signature.signature_s.size);
int length = wallet_ethereum_assemble_tx(&tx, &signature, raw_tx_bytes);
int8_to_char((uint8_t *) raw_tx_bytes, length, rawTx);
printf("raw transaction: %s\n", rawTx);
}
int main() {
assembleTx();
return 0;
}