From c14a9532f3b942aa8e9c06549382e277250aadc6 Mon Sep 17 00:00:00 2001 From: Bass Jobsen Date: Sun, 26 Aug 2018 13:17:23 +0200 Subject: [PATCH 1/2] add code for proposals and gateways, used it with https://github.com/AschPlatform/asch-js/pull/21 --- README.md | 10 ++++- plugins/api.js | 117 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 122 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0812f3f..f6013ad 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,15 @@ n stable peerstat analyze block height of all peers delegatestat analyze delegates status ipstat analyze peer ip info - + propose [options] propose a proposal + registergateway [options] register a gateway + activateproposal [options] activate a proposal + initgateway [options] initiate a gateway + updatemember [options] update a member of a gateway + revokegateway [options] revoke a gateway + registermember [options] register a member for a gateway + + Options: -h, --help output usage information diff --git a/plugins/api.js b/plugins/api.js index d116e08..6c3725b 100644 --- a/plugins/api.js +++ b/plugins/api.js @@ -200,8 +200,7 @@ function sendMoney(options) { secret: options.secret, secondSecret: options.secondSecret, args: [ - 'XAS', - options.amount, + Number(options.amount), options.to ] }); @@ -216,7 +215,6 @@ function setName(options) { options.secret, options.secondSecret ); - console.log(JSON.stringify(trs)) getApi().broadcastTransaction(trs, function (err, result) { console.log(err || result.transactionId) }); @@ -360,6 +358,65 @@ function transaction(options) { }); } +/* function propose(options) { + var trs = aschJS.proposal.propose({ + title: options.title, + desc: options.desc, + endHeight: options.endHeight + },options.secret, options.secondSecret) + getApi().broadcastTransaction(trs, function (err, result) { + console.log(err || result.transactionId) + }); +} */ + +function registergateway(options) { + var trs = aschJS.proposal.registergateway({ + title: options.title, + desc: options.desc, + endHeight: Number(options.endHeight), + name: options.name, + symbol: options.symbol, + currencyDesc: options.currencyDesc, + precision: options.precision || 8, + minimumMembers: options.minimumMembers || 3, + updateInterval: options.updateInterval || 8640 + },options.secret, options.secondSecret) + getApi().broadcastTransaction(trs, function (err, result) { + console.log(err || result.transactionId) + }); +}activateproposal + +function activateproposal(options) { + var trs = aschJS.proposal.activate({ + tid: options.tid + },options.secret, options.secondSecret) + getApi().broadcastTransaction(trs, function (err, result) { + console.log(err || result.transactionId) + }); +} + +function initgateway(options) { + var trs = aschJS.proposal.initgateway({ + name: options.name, + members: JSON.parse('[' + options.members.split(',').map(function(word){ + return '"' + word.trim() + '"'; +}).join(',') + +']') + },options.secret, options.secondSecret) + getApi().broadcastTransaction(trs, function (err, result) { + console.log(err || result.transactionId) + }); +} + +function registermember(options) { + var trs = aschJS.gateway.registerMember({ + gateway: options.gateway + },options.secret, options.secondSecret) + getApi().broadcastTransaction(trs, function (err, result) { + console.log(err || result.transactionId) + }); +} + function lock(options) { var trs = aschJS.transaction.createLock(options.height, options.secret, options.secondSecret) getApi().broadcastTransaction(trs, function (err, result) { @@ -728,4 +785,56 @@ module.exports = function(program) { .option("-m, --message ", "") .option("-f, --fee ", "transaction fee") .action(transaction); -} \ No newline at end of file + +/* Only proposals with a type (topic) set can be done + program + .command("propose") + .description("propose a proposal") + .option("-e, --secret ", "") + .option("-t, --title ", "Title of the proposal (10-100 chars)") + .option("-d, --desc <description>", "Description of the proposal") + .option("-h, --endHeight <height>", "Proposal end date") + .action(propose); +*/ + + program + .command("registergateway") + .description("register a gateway") + .option("-e, --secret <secret>", "") + .option("-s, --secondSecret <secret>", "") + .option("-t, --title <title>", "Title of the Gateway (10-100 chars)") + .option("-d, --desc <description>", "Description of the Gateway") + .option("-h, --endHeight <height>", "Proposal end date") + .option("-n, --name <name>", "Name of the currency (3-16 uppercase and lowercase chars)") + .option("-s, --symbol <symbol>", "Howto call the issued currency") + .option("-c, --currencyDesc <Description>", "description of the currency") + .option("-p, --precision <precision>", "precision of the currency") + .option("-m, --minimumMembers <minimumMembers>", "The minimum number of members of the gateway, the range of this value should be an integer between 3-33") + .option("-u, --updateInterval <updateInterval>", "update frequency, this value Should be greater than or equal to 8640") + .action(registergateway); + + program + .command("activateproposal") + .description("activate a proposal") + .option("-e, --secret <secret>", "") + .option("-s, --secondSecret <secret>", "") + .option("-t, --tid <tid>", "The tid of the proposal") + .action(activateproposal); + + program + .command("initgateway") + .description("register a gateway") + .option("-e, --secret <secret>", "") + .option("-s, --secondSecret <secret>", "") + .option("-n, --name <name>", "Name of the currency / gateway (3-16 uppercase and lowercase chars)") + .option("-m, --members <addressMember1, addressMember2, addressMember3, ...>", "csv list of the member addresses") + .action(initgateway); + + program + .command("registermember") + .description("register a member for a gateway") + .option("-e, --secret <secret>", "") + .option("-s, --secondSecret <secret>", "") + .option("-g, --gateway <gateway>", "the name of the gateway") + .action(registermember); +} From 53e55172083ecc39ab78863e6f9299eeea13cd5e Mon Sep 17 00:00:00 2001 From: Bass Jobsen <bass@w3masters.nl> Date: Tue, 28 Aug 2018 01:26:16 +0200 Subject: [PATCH 2/2] add voting for a proposal --- README.md | 5 +++-- plugins/api.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f6013ad..7819c38 100644 --- a/README.md +++ b/README.md @@ -68,14 +68,15 @@ n stable peerstat analyze block height of all peers delegatestat analyze delegates status ipstat analyze peer ip info - <strike>propose [options] propose a proposal</strike> + ~~propose [options] propose a proposal~~ registergateway [options] register a gateway activateproposal [options] activate a proposal initgateway [options] initiate a gateway updatemember [options] update a member of a gateway revokegateway [options] revoke a gateway registermember [options] register a member for a gateway - + upvoteproposal [options] vote for a proposal + Options: diff --git a/plugins/api.js b/plugins/api.js index 6c3725b..0e80769 100644 --- a/plugins/api.js +++ b/plugins/api.js @@ -395,6 +395,15 @@ function activateproposal(options) { }); } +function upvoteproposal(options) { + var trs = aschJS.proposal.upvote({ + tid: options.tid + },options.secret, options.secondSecret) + getApi().broadcastTransaction(trs, function (err, result) { + console.log(err || result.transactionId) + }); +} + function initgateway(options) { var trs = aschJS.proposal.initgateway({ name: options.name, @@ -837,4 +846,12 @@ module.exports = function(program) { .option("-s, --secondSecret <secret>", "") .option("-g, --gateway <gateway>", "the name of the gateway") .action(registermember); + + program + .command("upvoteproposal") + .description("activate a proposal") + .option("-e, --secret <secret>", "") + .option("-s, --secondSecret <secret>", "") + .option("-t, --tid <tid>", "The tid of the proposal") + .action(upvoteproposal); }