UNPKG

1.35 kBJavaScriptView Raw
1const {Block, Transaction} = require("../protocol/core/Tron_pb");
2const {TransferContract} = require("../protocol/core/Contract_pb");
3
4
5function deserializeTransaction(tx) {
6 let contractType = Transaction.Contract.ContractType;
7
8 let contractList = tx.getRawData().getContractList();
9 for (let contract of contractList) {
10 let any = contract.getParameter();
11
12 switch (contract.getType()) {
13
14 case contractType .ACCOUNTCREATECONTRACT: {
15 // contractType = contractType .ACCOUNTCREATECONTRACT;
16
17 let obje = any.unpack(AccountCreateContract.deserializeBinary, "protocol.AccountCreateContract");
18
19 return {};
20 }
21
22 case contractType .TRANSFERCONTRACT: {
23 // let contractType = contractType .TRANSFERCONTRACT;
24
25 let obje = any.unpack(TransferContract.deserializeBinary, "protocol.TransferContract");
26
27 let owner = obje.getOwnerAddress();
28 let ownerHex = byteArray2hexStr(owner);
29 let ownerHexSix = ownerHex.substr(0, 6) + '...';
30
31 let to = obje.getToAddress();
32 let toHex = byteArray2hexStr(to);
33
34 let toHexSix = toHex.substr(0, 6) + '...';
35
36 let amount = obje.getAmount() / 1000000;
37
38 return {
39 from: ownerHex,
40 to: toHex,
41 amount,
42 };
43 }
44 }
45 }
46}
47
48module.exports = {
49 deserializeTransaction
50};