28 |
30 |
|
return Data(data); |
29 |
31 |
|
} |
30 |
32 |
|
|
|
33 |
+ |
static inline ByteArray* byteArray(Data& amount) { |
|
34 |
+ |
auto array = new ByteArray(); |
|
35 |
+ |
amount = prependZero(amount); |
|
36 |
+ |
array->set_data(amount.data(), amount.size()); |
|
37 |
+ |
return array; |
|
38 |
+ |
} |
|
39 |
+ |
|
|
40 |
+ |
static inline ByteArray* byteArray(const void* data, size_t size) { |
|
41 |
+ |
auto array = new ByteArray(); |
|
42 |
+ |
array->set_data(data, size); |
|
43 |
+ |
return array; |
|
44 |
+ |
} |
31 |
45 |
|
|
32 |
46 |
|
Data Signer::getPreImage(const Proto::SigningInput& input, Address& address) noexcept { |
33 |
47 |
|
auto internal = ZilliqaMessage::ProtoTransactionCoreInfo(); |
34 |
48 |
|
const auto key = PrivateKey(Data(input.private_key().begin(), input.private_key().end())); |
35 |
|
- |
if (!Address::decode(input.to_address(), address)) { |
|
49 |
+ |
if (!Address::decode(input.to(), address)) { |
36 |
50 |
|
// invalid input address |
37 |
51 |
|
return Data(0); |
38 |
52 |
|
} |
39 |
53 |
|
const auto pubKey = key.getPublicKey(TWPublicKeyTypeSECP256k1); |
|
54 |
+ |
auto gasPrice = Data(input.gas_price().begin(), input.gas_price().end()); |
40 |
55 |
|
|
41 |
56 |
|
internal.set_version(input.version()); |
42 |
57 |
|
internal.set_nonce(input.nonce()); |
43 |
58 |
|
internal.set_toaddr(address.getKeyHash().data(), address.getKeyHash().size()); |
44 |
|
- |
|
45 |
|
- |
auto sender = new ZilliqaMessage::ByteArray(); |
46 |
|
- |
sender->set_data(pubKey.bytes.data(), pubKey.bytes.size()); |
47 |
|
- |
internal.set_allocated_senderpubkey(sender); |
48 |
|
- |
|
49 |
|
- |
auto amountArray = new ZilliqaMessage::ByteArray(); |
50 |
|
- |
auto amount = Data(input.amount().begin(), input.amount().end()); |
51 |
|
- |
amount = prependZero(amount); |
52 |
|
- |
amountArray->set_data(amount.data(), amount.size()); |
53 |
|
- |
internal.set_allocated_amount(amountArray); |
54 |
|
- |
|
55 |
|
- |
auto gasPriceArray = new ZilliqaMessage::ByteArray(); |
56 |
|
- |
auto gasPrice = Data(input.gas_price().begin(), input.gas_price().end()); |
57 |
|
- |
gasPrice = prependZero(gasPrice); |
58 |
|
- |
gasPriceArray->set_data(gasPrice.data(), gasPrice.size()); |
59 |
|
- |
internal.set_allocated_gasprice(gasPriceArray); |
60 |
|
- |
|
61 |
59 |
|
internal.set_gaslimit(input.gas_limit()); |
|
60 |
+ |
internal.set_allocated_senderpubkey(byteArray(pubKey.bytes.data(), pubKey.bytes.size())); |
|
61 |
+ |
internal.set_allocated_gasprice(byteArray(gasPrice)); |
|
62 |
+ |
|
|
63 |
+ |
Data amount; |
|
64 |
+ |
switch (input.transaction().message_oneof_case()) { |
|
65 |
+ |
case Proto::Transaction::kTransfer: { |
|
66 |
+ |
const auto transfer = input.transaction().transfer(); |
|
67 |
+ |
amount = Data(transfer.amount().begin(), transfer.amount().end()); |
|
68 |
+ |
break; |
|
69 |
+ |
} |
|
70 |
+ |
case Proto::Transaction::kRawTransaction: { |
|
71 |
+ |
const auto raw = input.transaction().raw_transaction(); |
|
72 |
+ |
amount = Data(raw.amount().begin(), raw.amount().end()); |
|
73 |
+ |
if (!raw.code().empty()) { |
|
74 |
+ |
internal.set_code(raw.code()); |
|
75 |
+ |
} |
|
76 |
+ |
if (!raw.data().empty()) { |
|
77 |
+ |
internal.set_data(raw.data()); |
|
78 |
+ |
} |
|
79 |
+ |
break; |
|
80 |
+ |
} |
|
81 |
+ |
default: break; |
|
82 |
+ |
} |
|
83 |
+ |
|
|
84 |
+ |
internal.set_allocated_amount(byteArray(amount)); |
62 |
85 |
|
|
63 |
86 |
|
const auto serialized = internal.SerializeAsString(); |
64 |
87 |
|
return Data(serialized.begin(), serialized.end()); |