-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from a1300/finish_proposals_gateways
feat(proposal): Finish proposal and gateway features, closes #35
- Loading branch information
Showing
6 changed files
with
1,006 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
var Buffer = require("buffer/").Buffer; | ||
var should = require("should"); | ||
var asch = require("../index.js"); | ||
|
||
describe("gateway.js", () => { | ||
var gateway = asch.gateway; | ||
|
||
it("should be ok", () => { | ||
(gateway).should.be.ok; | ||
}); | ||
|
||
it("should be object", () => { | ||
(gateway).should.be.type("object"); | ||
}); | ||
|
||
describe("#registerMember", () => { | ||
var registerMember; | ||
var trs; | ||
|
||
beforeEach(() => { | ||
registerMember = asch.gateway.registerMember; | ||
let publicKey = asch.crypto.getKeys("secret").publicKey; | ||
trs = registerMember("name", publicKey, "secret"); | ||
}); | ||
|
||
afterEach(() => { | ||
trs = null; | ||
}); | ||
|
||
it("should have property registerMember", () => { | ||
(gateway).should.have.property("registerMember"); | ||
}); | ||
|
||
it("should be function", () => { | ||
(registerMember).should.be.type("function"); | ||
}); | ||
|
||
it("should create registerMember transaction", () => { | ||
(trs).should.be.ok; | ||
(trs).should.be.type("object"); | ||
}); | ||
|
||
describe("returned registerMember transaction", () => { | ||
it("should have id as string", () => { | ||
(trs.id).should.be.type("string"); | ||
}); | ||
|
||
it("should have type as number and equal 401", () => { | ||
(trs.type).should.be.type("number").and.equal(401); | ||
}); | ||
|
||
it("should have args as array with 2 items", () => { | ||
(trs.args).should.be.an.Array().with.a.lengthOf(2); | ||
}); | ||
|
||
it("should have gateway-name as first item", () => { | ||
should(trs.args[0]).be.type("string").and.equal("name"); | ||
}); | ||
|
||
it("should have publicKey from new member as second item", () => { | ||
should(trs.args[1]).be.type("string").and.equal("5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09"); | ||
}); | ||
|
||
it("should have fee and equal 100 XAS", () => { | ||
(trs.fee).should.be.type("number").and.equal(100 * 1e8); | ||
}); | ||
|
||
it("should have senderPublicKey as hex string", () => { | ||
(trs.senderPublicKey).should.be.type("string").and.match(function (given) { | ||
try { | ||
new Buffer(trs.senderPublicKey, "hex"); | ||
} catch (e) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
}); | ||
|
||
it("should have one signature as hex string in signatures array", () => { | ||
(trs.signatures[0]).should.be.type("string").and.match(() => { | ||
try { | ||
new Buffer(trs.signatures[0], "hex") | ||
} catch (e) { | ||
return false; | ||
} | ||
return true; | ||
}) | ||
}); | ||
|
||
it("should be signed correctly", () => { | ||
var result = asch.crypto.verify(trs); | ||
|
||
(result).should.be.ok; | ||
}); | ||
|
||
it("should not be signed correctly now", () => { | ||
trs.amount = 24242424; | ||
var result = asch.crypto.verify(trs); | ||
(result).should.be.not.ok; | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.