Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
83 lines (57 loc) · 1.88 KB

File metadata and controls

83 lines (57 loc) · 1.88 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
'use strict'
const ChainsqlAPI = require('../src/index');
const c = new ChainsqlAPI();
var user = {
secret: "xxeJcpbcFyGTFCxiGjeDEw1RCimFQ",
address: "z44fybVuUn8jZxZRHpc3pJ62KQJgSEjzjk",
publicKey: "cB4MLVsyn5MnoYHhApEyGtPCuEf9PAGDopmpB7yFwTbhUtzrjRRT"
}
var owner = {
secret: "xnoPBzXtMeMyMHUVTgbuqAfg1SUTb",
address: "zHb9CJAWyB4zj91VRWn96DkukG4bwdtyTh"
}
var sTableName = "tTable1";
main();
async function main() {
try {
await c.connect('ws://127.0.0.1:6006');
console.log('连接成功');
c.as(owner);
await testTxSign();
console.log('测试结束');
} catch (e) {
console.error(e);
}
}
async function testTxSign() {
var rawCreate = [
{ 'field': 'id', 'type': 'int', 'length': 11, 'PK': 1, 'NN': 1 },
{ 'field': 'name', 'type': 'varchar', 'length': 50, 'default': "" },
{ 'field': 'age', 'type': 'int' }
]
var option = {
confidential: false
}
var rawInsert = [
{ 'id': 1, 'age': 333, 'name': 'hello' },
{ 'id': 2, 'age': 444, 'name': 'sss' },
{ 'id': 3, 'age': 555, 'name': 'rrr' }
];
var rawGrant = { select: true, insert: false, update: false, delete: true };
try {
// payment
let paymentSign = await c.pay(user.address, 2000).txSign();
console.log("payment Tx sign : " + JSON.stringify (paymentSign));
// create table
// let createTableSign = await c.createTable(sTableName, rawCreate, option).txSign();
// console.log("create table Tx sign : " + JSON.stringify(createTableSign));
// insert/grant 等 签名交易的生成需要保证表已存在
// let insertTableSign = await c.table(sTableName).insert(rawInsert).txSign();
// console.log("insert table Tx sign : " + JSON.stringify(insertTableSign));
// grant
var grantSign = await c.grant(sTableName, user.address, rawGrant, user.publicKey).txSign();
console.log("insert table Tx sign : " + JSON.stringify(grantSign));
} catch (error) {
console.error(error);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.