Skip to content

Commit 8ca7af1

Browse files
committed
Add account authorization
1 parent 42b9866 commit 8ca7af1

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ChainsqlAPI.prototype.connect = function (url, cb) {
9090
this.event = new EventManager(this);
9191
if ((typeof cb) != 'function') {
9292
return con.connect();
93-
} else {
93+
} else {
9494
con.connect().then(function (data) {
9595
cb(null, data)
9696
}).catch(function (err) {
@@ -292,6 +292,11 @@ ChainsqlAPI.prototype.trustSet = function (amount) {
292292
return ripple.trustSet(amount);
293293
}
294294

295+
ChainsqlAPI.prototype.accountAuthorize = function (nFlag, bSet, account) {
296+
let ripple = new Ripple(this);
297+
return ripple.accountAuthorize(nFlag, bSet, account);
298+
}
299+
295300
ChainsqlAPI.prototype.escrowCreate = function (sDestAddr, amount, opt) {
296301
let ripple = new Ripple(this);
297302
return ripple.escrowCreate(sDestAddr, amount, opt);

src/ripple.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ Ripple.prototype.prepareJson = function () {
108108
else if (transactionType === "PayToContract") {
109109
return chainsqlLibUtils.prepareTransaction(txJson, this.ChainsqlAPI.api, {});
110110
}
111+
else if (transactionType === "Authorize") {
112+
return chainsqlLibUtils.prepareTransaction(txJson, this.ChainsqlAPI.api, {});
113+
}
111114
}
112115

113116
Ripple.prototype.preparePayment = function (account, amount, memos) {
@@ -273,6 +276,21 @@ Ripple.prototype.trustSet = function (amount) {
273276
return this;
274277
}
275278

279+
Ripple.prototype.accountAuthorize = function (nFlag, bSet, account) {
280+
var self = this;
281+
var setting = {};
282+
setting.Account = this.ChainsqlAPI.connect.address;
283+
if(bSet)
284+
setting.SetFlag = nFlag;
285+
else
286+
setting.ClearFlag = nFlag;
287+
setting.TransactionType = "Authorize";
288+
setting.Destination = account;
289+
this.txType = "Authorize";
290+
this.txJSON = setting;
291+
return this;
292+
}
293+
276294
Ripple.prototype.escrowCreate = function (sDestAddr, amount, opt) {
277295
var _amount = { value: 0 }
278296
var type = typeof(amount);

test/testRipple.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var user3 = {
3232

3333
var tagStep = {
3434
active: 1, gateWay: 2, escrow: 3,
35-
balances: 4, getLedger: 5, getTxs: 6
35+
balances: 4, getLedger: 5, getTxs: 6,authorize:7,
3636
}
3737
var sCurrency = "aaa"
3838
var whiteLists = [
@@ -45,19 +45,20 @@ main();
4545
async function main() {
4646
// let res = await c.connect('ws://101.201.40.124:5006');
4747
let res = await c.connect('ws://localhost:5510');
48-
await c.setSchema("8B0BA6D8848C76E19433EE90E2A88210E403339F2C5AC750271EFC862A173894");
48+
// await c.setSchema("8B0BA6D8848C76E19433EE90E2A88210E403339F2C5AC750271EFC862A173894");
4949

5050
c.as(root);
5151
c.setRestrict(true);
5252
/**************************************/
53-
let nStep = tagStep.gateWay;
53+
let nStep = tagStep.authorize;
5454
switch (nStep) {
5555
case tagStep.active: testActive(); break;// 激活若干账户
5656
case tagStep.gateWay: testGateWay(); break;//部署网管,信任,发行币转账
5757
case tagStep.escrow: testEscrow(); break;
5858
case tagStep.balances: testBalances(); break;//账户余额
5959
case tagStep.getTxs: testTransactions(); break;
6060
case tagStep.getLedger: testGetLedger(); break;
61+
case tagStep.authorize: testAuthorize();break;
6162
default: break;
6263
}
6364
/**************************************/
@@ -251,3 +252,15 @@ var testGetLedger = async function () {
251252
console.log("err:", err);
252253
});
253254
}
255+
256+
var testAuthorize = async function(){
257+
try {
258+
//参数: 授权/取消授权哪个权限、是否是授权、给谁授权
259+
// 12 转账的权限, 13 部署合约的权限, 14 创建表的权限, 15发行数字资产的权限, 16 admin权限
260+
var ret = await c.accountAuthorize(12, true, user2.address).submit({ expect: 'validate_success' });
261+
console.log("accountAuthorize ", ret);
262+
} catch (error) {
263+
console.error("accountAuthorize ", error);
264+
}
265+
266+
}

0 commit comments

Comments
 (0)