-
Notifications
You must be signed in to change notification settings - Fork 6
/
grpc_api_example.js
86 lines (72 loc) · 2.5 KB
/
grpc_api_example.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const { RClient } = require("..");
const { ec } = require("elliptic");
const assert = require("assert").strict;
const secp256k1 = new ec("secp256k1");
const {
MAINNET_SERVER,
READONLY_SERVER,
TESTNET_OBSERVER,
TESTNET_SERVER,
} = require("./server");
const key = secp256k1.keyFromPrivate(
"ff4566482c3df328256a503e4f99df4a0a120c12523293546284f1ef30d7cf4b",
"hex"
);
const blockHash =
"0a826ff9f1e8020d663e29e52768c2714f171b48e8ab84ee93a29fa87a9a409c";
const term = "@1!(2)";
const exploratory_term = 'new return in{return!("a")}';
const deployID = '30440220057f2a3f2d02b9cf42002a3dd56dba2eac9c83d200e1606e6607fac79f388a6d02204528c8fba9a49d0323fd4bae1ae005d790453d7e4e4b3f09a93b49c0e95285e7'
async function main () {
var client = new RClient(TESTNET_OBSERVER[0], 40401);
//get the latest 10 block in the rnode
var blockInfos = await client.getBlocks(10);
console.log("get blockInfos");
assert.equal(blockInfos.length, 10);
const latestBlockNumber = blockInfos[0].blockinfo.blocknumber
//# get the detailed info in the rnode
var blockInfo = await client.getBlock(blockHash);
console.log("get block ");
assert.equal(blockInfo.blockinfo.blockinfo.blockhash, blockHash);
// last finalized block
const finalized = await client.lastFinalizedBlock()
// confirm if a block is finalized
assert(await client.isFinalized(blockHash));
console.log("is finalized");
// get blocks from blockNumber latestBlockNumber-10 to blockNumber latestBlockNumber
var blockInfosAtHeights = await client.getBlocksByHeights(latestBlockNumber - 10, latestBlockNumber);
console.log("get blocks by heights");
// find block info by the deployId
var blockByDeployId = await client.findDeploy(deployID)
var result = await client.exploratoryDeploy(exploratory_term);
assert.equal(result.result.postblockdataList[0].exprsList[0].gString, "a");
console.log("exploratory deploy");
// remember to close your client when you are done to save resource
client.closeClient()
var testNetClient = new RClient(TESTNET_SERVER[0], 40401);
var deploy = await testNetClient.deploy(
key,
term,
1,
100000,
1000,
Date.now()
);
console.log("testnet deploy");
console.log(deploy);
var deploy2 = await testNetClient.deployWithAfterVABNFilled(
key,
term,
1,
100000,
Date.now()
);
console.log(deploy2);
// remember to close your client when you are done to save resource
testNetClient.closeClient()
}
(async () => {
await main();
})().catch((e) => {
console.log(e);
});