This repository has been archived by the owner on Dec 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathp2p_raw.js
68 lines (62 loc) · 3.01 KB
/
p2p_raw.js
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
// Use following require statement when using npm.
// const { libra } = require("gopherjs-libra");
const { libra } = require("../../gopherjs-libra/gopherjs-libra.js");
const fromHexString = hexString =>
new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
const toHexString = bytes =>
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
const defaultServer = "http://hk2.wutj.info:38080",
waypoint = "0:4d4d0feaa9378069f8fcee71980e142273837e108702d8d7f93a8419e2736f3f";
var senderAddr = fromHexString("42f5745128c05452a0c68272de8042b1"),
priKey = fromHexString("996911072ee011ffa44a1325e0da593ff3b9374e255115f223cbdffb6bfa0bcfba60d1f8edd6923f59cf9125d3ac80e389afa4e2b8d0e4f1183a30a0270fde71"),
recvAddr = fromHexString("5817cd6e6e84c110c43efca22df54172"),
recvAuthKeyPrefix = fromHexString("26c7bfaa8e0f32206f35bf6d44b43c9c");
var p2pTransactionCode = new Uint8Array([
0xa1, 0x1c, 0xeb, 0x0b, 0x01, 0x00, 0x07, 0x01, 0x46, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x03, 0x4a, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
0x00, 0x04, 0x56, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x58,
0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x07, 0x61, 0x00, 0x00, 0x00,
0x29, 0x00, 0x00, 0x00, 0x06, 0x8a, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
0x00, 0x09, 0x9a, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x01, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x03, 0x00, 0x01,
0x01, 0x01, 0x00, 0x02, 0x03, 0x05, 0x0a, 0x02, 0x03, 0x00, 0x01, 0x09,
0x00, 0x06, 0x3c, 0x53, 0x45, 0x4c, 0x46, 0x3e, 0x0c, 0x4c, 0x69, 0x62,
0x72, 0x61, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x0f, 0x70, 0x61,
0x79, 0x5f, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x73, 0x65, 0x6e, 0x64, 0x65,
0x72, 0x04, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0xff, 0xff, 0x03, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x0b, 0x01, 0x0a,
0x02, 0x3e, 0x00, 0x02
]);
var client = libra.client(defaultServer, waypoint)
client.queryAccountSequenceNumber(senderAddr)
.then(r => {
var txn = {
"senderAddr": senderAddr,
"senderPrivateKey": priKey,
"senderSeq": r,
"payload": {
"code": p2pTransactionCode,
"args": [
recvAddr, // receiving addr
{"type": "bytes", "value": recvAuthKeyPrefix},
2 * 1000000 // amount uLibra
]
},
"maxGasAmount": 500000,
"gasUnitPrice": 0,
"expirationTimestamp": parseInt(Date.now() / 1000) + 60,
};
console.log(txn)
return client.submitRawTransaction(txn);
})
.then(r => {
console.log("Polling sequence number until ", r)
return client.pollSequenceUntil(senderAddr, r, parseInt(Date.now() / 1000) + 60)
})
.then(r => {
console.log("done.")
})
.catch(e => {
console.log("Error:" + e)
})