From 142a64f8e45ca356f6ea3460795f4a1466ef4800 Mon Sep 17 00:00:00 2001 From: Bass Jobsen Date: Fri, 7 Sep 2018 11:21:57 +0200 Subject: [PATCH] add code for poposals and gateways --- index.js | 2 + lib/transactions/gateway.js | 17 +++++++ lib/transactions/proposal.js | 88 ++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 lib/transactions/gateway.js create mode 100644 lib/transactions/proposal.js diff --git a/index.js b/index.js index 1d3842b..13ea4e7 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,8 @@ module.exports = { transaction : require("./lib/transactions/transaction.js"), vote : require("./lib/transactions/vote.js"), uia: require("./lib/transactions/uia.js"), + proposal: require("./lib/transactions/proposal.js"), + gateway: require("./lib/transactions/gateway.js"), options: require("./lib/options.js"), utils: { slots: require("./lib/time/slots.js"), diff --git a/lib/transactions/gateway.js b/lib/transactions/gateway.js new file mode 100644 index 0000000..82ade01 --- /dev/null +++ b/lib/transactions/gateway.js @@ -0,0 +1,17 @@ +var crypto = require("./crypto.js") +var transaction = require('./transaction.js') + +function registerMember(options, secret, secondSecret) { + let keys = crypto.getKeys(secret); + return transaction.createTransactionEx({ + type: 401, + fee: 100 * 1e8, + secret: secret, + secondSecret, secondSecret, + args: [options.gateway, keys.publicKey] + }) +} + +module.exports = { + registerMember: registerMember +} diff --git a/lib/transactions/proposal.js b/lib/transactions/proposal.js new file mode 100644 index 0000000..6083a3c --- /dev/null +++ b/lib/transactions/proposal.js @@ -0,0 +1,88 @@ +var crypto = require("./crypto.js") +var transaction = require('./transaction.js') + +/*function propose(options, secret, secondSecret) { + var keys = crypto.getKeys(secret); + return transaction.createTransactionEx({ + type: 300, + fee: 10 * 1e8, + secret: secret, + secondSecret, secondSecret, + args: [options.title, options.desc, null, null, options.endHeight] + }) +}*/ + +function registergateway(options, secret, secondSecret) { + + let keys = crypto.getKeys(secret); + let currency = { + symbol : options.symbol, + desc: options.currencyDesc, + precision : options.precision + } + // construct this content + let content = { + name : options.name, + desc : options.desc, + minimumMembers: options.minimumMembers, + updateInterval: options.updateInterval, + currency: currency + } + return transaction.createTransactionEx({ + type: 300, + fee: 10 * 1e8, + secret: secret, + secondSecret, secondSecret, + args: [options.title, options.desc, 'gateway_register', content, options.endHeight] + }) +} + +function initgateway(options, secret, secondSecret) { + + let keys = crypto.getKeys(secret); + // construct this content + let content = { + gateway : options.name, + members: options.members + } + + return transaction.createTransactionEx({ + type: 300, + fee: 10 * 1e8, + secret: secret, + secondSecret, secondSecret, + args: ['xxxxxxxxxx', '', 'gateway_init', content, 500000] + }) +} + +function activate(options, secret, secondSecret) { + + let keys = crypto.getKeys(secret); + return transaction.createTransactionEx({ + type: 302, + fee: 0 * 1e8, + secret: secret, + secondSecret, secondSecret, + args: [options.tid] + }) +} + +function upvote(options, secret, secondSecret) { + + let keys = crypto.getKeys(secret); + return transaction.createTransactionEx({ + type: 301, + fee: 1e7, // 0.1 * 1e8 + secret: secret, + secondSecret, secondSecret, + args: [options.tid] + }) +} + +module.exports = { + //propose: propose + registergateway: registergateway, + initgateway: initgateway, + activate: activate, + upvote: upvote +}