This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
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 #110 from zhiqiang-bianjie/develop
R4R: Support gov deposit&vote Tx
- Loading branch information
Showing
10 changed files
with
779 additions
and
81 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
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
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,65 +1,139 @@ | ||
'use strict'; | ||
|
||
const Builder = require("../../builder"); | ||
const Config = require('../../../config'); | ||
const Root = require('./tx/tx'); | ||
const BECH32 = require('bech32'); | ||
const Utils = require('../../util/utils'); | ||
const Amino = require('../base'); | ||
const Bank = require('./bank'); | ||
|
||
class SubmitProposalMsg extends Builder.Msg{ | ||
constructor(title, description, proposalKind,proposer,deposit) { | ||
super(); | ||
this.Title = title; | ||
this.Description = description; | ||
this.ProposalKind = proposalKind; | ||
this.Proposer = proposer; | ||
this.InitialDeposit = deposit; | ||
} | ||
|
||
GetSignBytes() { | ||
let msg = { | ||
"Title": this.Title, | ||
"Description": this.Description, | ||
"ProposalKind": this.ProposalKind, | ||
"Proposer": this.Proposer, | ||
"InitialDeposit": this.InitialDeposit | ||
}; | ||
let sortMsg = Utils.sortObjectKeys(msg); | ||
return Amino.MarshalJSON(this.Type(),sortMsg) | ||
} | ||
ValidateBasic() { | ||
if (Utils.isEmpty(this.Title)){ | ||
throw new Error("Title is empty"); | ||
} | ||
const voteOptionMapping = { | ||
0x00: 'Empty', | ||
0x01: 'Yes', | ||
0x02: 'Abstain', | ||
0x03: 'No', | ||
0x04: 'NoWithVeto' | ||
}; | ||
|
||
if (Utils.isEmpty(this.Description)){ | ||
throw new Error("Description is empty"); | ||
} | ||
const MsgDeposit = Root.irisnet.tx.MsgDeposit; | ||
MsgDeposit.prototype.type = Config.iris.tx.deposit.prefix; | ||
MsgDeposit.prototype.GetSignBytes = function () { | ||
let depositor = BECH32.encode(Config.iris.bech32.accAddr, this.depositor); | ||
let signMsg = { | ||
proposal_id: `${this.proposalID}`, | ||
depositor: depositor, | ||
amount: this.amount | ||
}; | ||
return Utils.sortObjectKeys(signMsg); | ||
}; | ||
|
||
if (Utils.isEmpty(this.ProposalKind)){ | ||
throw new Error("delegation must great than 0"); | ||
} | ||
MsgDeposit.prototype.ValidateBasic = function () { | ||
if (Utils.isEmpty(this.amount)) { | ||
throw new Error("amount is empty"); | ||
} | ||
if (Utils.isEmpty(this.proposalID)) { | ||
throw new Error("proposal_id is empty"); | ||
} | ||
if (Utils.isEmpty(this.depositor)) { | ||
throw new Error("depositor is empty"); | ||
} | ||
}; | ||
|
||
if (Utils.isEmpty(this.Proposer)){ | ||
throw new Error("Proposer must great than 0"); | ||
} | ||
MsgDeposit.prototype.GetMsg = function () { | ||
let depositor = BECH32.fromWords(this.depositor); | ||
return { | ||
proposalID: this.proposalID, | ||
depositor: depositor, | ||
amount: this.amount | ||
} | ||
}; | ||
|
||
if (Utils.isEmpty(this.InitialDeposit)){ | ||
throw new Error("InitialDeposit must great than 0"); | ||
} | ||
MsgDeposit.prototype.GetDisplayContent = function () { | ||
let depositor = BECH32.encode(Config.iris.bech32.accAddr, this.depositor); | ||
return { | ||
i18n_tx_type: "i18n_deposit", | ||
i18n_proposal_id:this.proposalID, | ||
i18n_depositor: depositor, | ||
i18n_amount: this.amount | ||
} | ||
}; | ||
MsgDeposit.prototype.toJSON = function () { | ||
let depositor = BECH32.encode(Config.iris.bech32.accAddr, this.depositor); | ||
return { | ||
proposal_id: this.proposalID, | ||
depositor: depositor, | ||
amount: this.amount | ||
} | ||
}; | ||
|
||
Type(){ | ||
return "cosmos-sdk/MsgSubmitProposal"; | ||
const MsgVote = Root.irisnet.tx.MsgVote; | ||
MsgVote.prototype.type = Config.iris.tx.vote.prefix; | ||
MsgVote.prototype.GetSignBytes = function () { | ||
let voter = BECH32.encode(Config.iris.bech32.accAddr, this.voter); | ||
let signMsg = { | ||
proposal_id: `${this.proposalID}`, | ||
voter: voter, | ||
option: voteOptionMapping[this.option] | ||
}; | ||
return Utils.sortObjectKeys(signMsg); | ||
}; | ||
MsgVote.prototype.ValidateBasic = function () { | ||
if (Utils.isEmpty(this.option)) { | ||
throw new Error("option is empty"); | ||
} | ||
if (Utils.isEmpty(this.proposalID)) { | ||
throw new Error("proposal_id is empty"); | ||
} | ||
if (Utils.isEmpty(this.voter)) { | ||
throw new Error("voter is empty"); | ||
} | ||
} | ||
}; | ||
MsgVote.prototype.GetMsg = function () { | ||
let voter = BECH32.fromWords(this.voter); | ||
return { | ||
proposalID: this.proposalID, | ||
voter: voter, | ||
option: this.option | ||
} | ||
}; | ||
MsgVote.prototype.GetDisplayContent = function () { | ||
let voter = BECH32.encode(Config.iris.bech32.accAddr, this.voter); | ||
return { | ||
i18n_tx_type: "i18n_vote", | ||
i18n_proposal_id: this.proposalID, | ||
i18n_voter: voter, | ||
option: voteOptionMapping[this.option] | ||
} | ||
}; | ||
MsgVote.prototype.toJSON = function () { | ||
let voter = BECH32.encode(Config.iris.bech32.accAddr, this.voter); | ||
return { | ||
proposal_id: this.proposalID, | ||
voter: voter, | ||
option: voteOptionMapping[this.option] | ||
} | ||
}; | ||
|
||
module.exports = class Gov { | ||
static createMsgDeposit(req){ | ||
let coins = []; | ||
if (!Utils.isEmpty(req.msg.amount)) { | ||
req.msg.amount.forEach(function(item) { | ||
coins.push({ | ||
denom: item.denom, | ||
amount: Utils.toString(item.amount), | ||
}); | ||
}); | ||
} | ||
return new MsgDeposit({ | ||
proposalID: `${req.msg.proposal_id}`, | ||
depositor: BECH32.decode(req.from).words, | ||
amount: coins | ||
}) | ||
} | ||
|
||
// TODO | ||
static GetSubmitProposalMsg(acc, validatorAddr, coins, fee, gas, memo){ | ||
let stdFee = Bank.NewStdFee(fee, gas); | ||
let msg = new SubmitProposalMsg(acc.address, validatorAddr, coins); | ||
let signMsg = Bank.NewStdSignMsg(acc.chain_id, acc.account_number, acc.sequence, stdFee, msg,memo); | ||
return signMsg; | ||
static createMsgVote(req){ | ||
return new MsgVote({ | ||
proposalID: `${req.msg.proposal_id}`, | ||
voter: BECH32.decode(req.from).words, | ||
option: req.msg.option | ||
}) | ||
} | ||
}; | ||
}; |
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
Oops, something went wrong.