Skip to content

Commit

Permalink
feature(proposal): Finshed proposal and gateway features, closes Asch…
Browse files Browse the repository at this point in the history
  • Loading branch information
a1300 committed Sep 22, 2018
1 parent f8c72ec commit 98c2e0f
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 50 deletions.
4 changes: 2 additions & 2 deletions lib/transactions/gateway.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var crypto = require("./crypto.js")
var transaction = require('./transaction.js')

function registerMember(options, secret, secondSecret) {
function registerMember(gateway, memberPublicKey, secret, secondSecret) {
let keys = crypto.getKeys(secret);
return transaction.createTransactionEx({
type: 401,
fee: 100 * 1e8,
secret: secret,
secondSecret, secondSecret,
args: [options.gateway, keys.publicKey]
args: [gateway, memberPublicKey]
})
}

Expand Down
129 changes: 83 additions & 46 deletions lib/transactions/proposal.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,125 @@
var crypto = require("./crypto.js")
var transaction = require('./transaction.js')

/*function propose(options, secret, secondSecret) {
var keys = crypto.getKeys(secret);
function registerGateway(options, secret, secondSecret) {
// construct content
let content = {
name : options.gatewayName,
desc : options.gatewayDesc,
minimumMembers: options.minimumMembers || 3,
updateInterval: options.updateInterval || 8640,
currency: {
symbol : options.currencySymbol,
desc: options.currencyDesc,
precision : options.currencyPrecision
}
}

return transaction.createTransactionEx({
type: 300,
fee: 10 * 1e8,
secret: secret,
secondSecret, secondSecret,
args: [options.title, options.desc, null, null, options.endHeight]
type: 300,
fee: 10 * 1e8,
secret: secret,
secondSecret: secondSecret,
args: [
options.proposalTitle || 'title for gateway_register',
options.proposalDesc, 'gateway_register',
content,
options.proposalEndHeight
]
})
}*/
}

function registergateway(options, secret, secondSecret) {

let keys = crypto.getKeys(secret);
let currency = {
symbol : options.symbol,
desc: options.currencyDesc,
precision : options.precision
}
// construct this content
function initGateway(options, secret, secondSecret) {
// construct content
let content = {
name : options.name,
desc : options.desc,
minimumMembers: options.minimumMembers,
updateInterval: options.updateInterval,
currency: currency
gateway : options.gatewayName,
members: options.gatewayMembers
}

return transaction.createTransactionEx({
type: 300,
fee: 10 * 1e8,
secret: secret,
secondSecret, secondSecret,
args: [options.title, options.desc, 'gateway_register', content, options.endHeight]
secondSecret: secondSecret,
args: [
options.proposalTitle || 'title for gateway_init',
options.proposalDesc || 'desc for gateway_init',
'gateway_init',
content,
options.proposalEndHeight
]
})
}

function initgateway(options, secret, secondSecret) {

let keys = crypto.getKeys(secret);
// construct this content
function updateGatewayMember(options, secret, secondSecret) {
// construct content
let content = {
gateway : options.name,
members: options.members
gateway: options.gatewayName,
from: options.fromAddress,
to: options.toAddress
}

return transaction.createTransactionEx({
type: 300,
fee: 10 * 1e8,
secret: secret,
secondSecret, secondSecret,
args: ['xxxxxxxxxx', '', 'gateway_init', content, 500000]
secondSecret: secondSecret,
args: [
options.proposalTitle || 'title for gateway_update_member',
options.proposalDesc || 'desc for gateway_update_member',
'gateway_update_member',
content,
options.proposalEndHeight
]
})
}

function activate(options, secret, secondSecret) {
function revokeGateway(options, secret, secondSecret) {
// construct content
let content = {
gateway: options.gatewayName
}

return transaction.createTransactionEx({
type: 300,
fee: 10 * 1e8,
secret: secret,
secondSecret: secondSecret,
args: [
options.proposalTitle || 'title for gateway_revoke',
options.proposalDesc || 'desc for gateway_revoke',
'gateway_revoke',
content,
options.proposalEndHeight
]
})
}

let keys = crypto.getKeys(secret);
function activateProposal(tid, secret, secondSecret) {
return transaction.createTransactionEx({
type: 302,
fee: 0 * 1e8,
secret: secret,
secondSecret, secondSecret,
args: [options.tid]
secondSecret: secondSecret,
args: [tid]
})
}

function upvote(options, secret, secondSecret) {

let keys = crypto.getKeys(secret);
function upvoteProposal(tid, secret, secondSecret) {
return transaction.createTransactionEx({
type: 301,
fee: 1e7, // 0.1 * 1e8
secret: secret,
secondSecret, secondSecret,
args: [options.tid]
secondSecret: secondSecret,
args: [tid]
})
}

module.exports = {
//propose: propose
registergateway: registergateway,
initgateway: initgateway,
activate: activate,
upvote: upvote
registerGateway: registerGateway,
initGateway: initGateway,
updateGatewayMember: updateGatewayMember,
revokeGateway: revokeGateway,
activateProposal: activateProposal,
upvoteProposal: upvoteProposal
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"license": "ISC",
"types": "./types/index.d.ts",
"dependencies": {
"@types/node": "^10.9.4",
"@types/node": "=8.10.29",
"JSONStream": "=1.3.1",
"browserify-bignum": "=1.3.0-2",
"buffer": "=4.7.0",
Expand Down
60 changes: 59 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,62 @@ interface Uia {
createTransfer: (currency: string, amount: string, recipientId: string, message: string, secret: string, secondSecret?: string) => MainchainTransaction;
}

/*
proposal.js
*/
interface RegisterGatwayOptions {
gatewayName: string;
gatewayDesc: string;
minmumMembers?: number;
updateInterval?: number;
currencySymbol: string;
currencyDesc: string;
currencyPrecision: number;
proposalTitle?: string;
proposalDesc?: string;
proposalEndHeight: number;
}

interface InitGatewayOptions {
gatewayName: string;
gatewayMembers: string[];
proposalTitle?: string;
proposalDesc?: string;
proposalEndHeight: number;
}

interface UpdateGatewayMemberOptions {
gatewayName: string;
fromAddress: string;
toAddress: string;
proposalTitle?: string;
proposalDesc?: string;
proposalEndHeight: number;
}

interface RevokeGatewayOptions {
gatewayName: string;
proposalTitle?: string;
proposalDesc?: string;
proposalEndHeight: number;
}

interface Proposal {
registerGateway: (options: RegisterGatwayOptions, secret: string, secondSecret?: string) => MainchainTransaction;
initGateway: (options: InitGatewayOptions, secret: string, secondSecret?: string) => MainchainTransaction;
updateGatewayMember: (options: UpdateGatewayMemberOptions, secret: string, secondSecret?: string) => MainchainTransaction;
revokeGateway: (options: RevokeGatewayOptions, secret: string, secondSecret?: string) => MainchainTransaction;
activateProposal: (tid: string, secret: string, secondSecret?: string) => MainchainTransaction;
upvoteProposal: (tid: string, secret: string, secondSecret?: string) => MainchainTransaction;
}

/*
gateway.js
*/
interface Gateway {
registerMember: (gateway: string, memberPublicKey: string, secret: string, secondSecret?: string) => MainchainTransaction;
}

/*
options.js
*/
Expand Down Expand Up @@ -202,7 +258,9 @@ declare const asch_js: {
delegate: Delegate,
transaction: Transaction,
vote: Vote,
uia: Uia,
uia: Uia,
proposal: Proposal,
gateway: Gateway,
options: Options,
utils: {
slots: Slots,
Expand Down

0 comments on commit 98c2e0f

Please sign in to comment.