Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #118 from irisnet/develop
Browse files Browse the repository at this point in the history
R4R: prepare release v1.3.4
  • Loading branch information
zhangyelong authored Jan 14, 2020
2 parents 69818f9 + 5105c74 commit 555c87b
Show file tree
Hide file tree
Showing 23 changed files with 1,649 additions and 122 deletions.
22 changes: 19 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
"type": "withdraw_delegation_reward",
"prefix": "irishub/distr/MsgWithdrawDelegationReward"
},
"deposit": {
"type": "deposit",
"prefix": "irishub/gov/MsgDeposit"
},
"vote": {
"type": "vote",
"prefix": "irishub/gov/MsgVote"
},
"stdTx": {
"type": "",
"prefix": "irishub/bank/StdTx"
Expand Down Expand Up @@ -53,7 +61,7 @@
"keystore": {
"kdf": "pbkdf2",
"cipherAlg": "aes-128-ctr",
"c": 262144
"c": 10000
}
},
"cosmos": {
Expand Down Expand Up @@ -86,9 +94,17 @@
"type": "withdraw_validator_commission",
"prefix": "cosmos-sdk/MsgWithdrawValidatorCommission"
},
"deposit": {
"type": "deposit",
"prefix": "cosmos-sdk/MsgDeposit"
},
"vote": {
"type": "vote",
"prefix": "cosmos-sdk/MsgVote"
},
"stdTx": {
"type": "stdTx",
"prefix": "auth/StdTx"
"prefix": "cosmos-sdk/StdTx"
}
},
"bech32": {
Expand Down Expand Up @@ -119,4 +135,4 @@
"ethermint": "ethermint",
"cosmos": "cosmos"
}
}
}
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ function setNetwork(network){
}
return config
}

module.exports = {getCrypto,getBuilder,config,Codec};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "irisnet-crypto",
"version": "1.3.3",
"version": "1.3.4",
"description": "irisnet-crypto",
"main": "index.js",
"scripts": {
Expand All @@ -27,7 +27,7 @@
"bech32": "^1.1.3",
"bignumber.js": "^5.0.0",
"bip39": "^2.5.0",
"bn": "git+https://github.com/shineabel/bn.git",
"bn": "git+https://github.com/irisnet/bn.js.git#v4.12.0",
"create-hmac": "^1.1.7",
"ethereumjs-tx": "^1.3.0",
"ethereumjs-util": "^5.1.2",
Expand Down
6 changes: 5 additions & 1 deletion src/chains/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ amino.RegisterConcrete(R_Cosmos.cosmos.MsgWithdrawDelegatorReward, Config.cosmos
amino.RegisterConcrete(R_Cosmos.cosmos.MsgWithdrawValidatorCommission, Config.cosmos.tx.withdrawValidatorCommission.prefix);
amino.RegisterConcrete(R_Cosmos.cosmos.MsgUndelegate, Config.cosmos.tx.undelegate.prefix);
amino.RegisterConcrete(R_Cosmos.cosmos.MsgBeginRedelegate, Config.cosmos.tx.beginRedelegate.prefix);
amino.RegisterConcrete(R_Cosmos.cosmos.MsgDeposit, Config.cosmos.tx.deposit.prefix);
amino.RegisterConcrete(R_Cosmos.cosmos.MsgVote, Config.cosmos.tx.vote.prefix);
amino.RegisterConcrete(R_Cosmos.cosmos.StdTx, Config.cosmos.tx.stdTx.prefix);

amino.RegisterConcrete(null, Config.iris.amino.pubKey);
Expand All @@ -97,5 +99,7 @@ amino.RegisterConcrete(R_Iris.irisnet.tx.MsgBeginRedelegate, Config.iris.tx.rede
amino.RegisterConcrete(R_Iris.irisnet.tx.MsgBeginUnbonding, Config.iris.tx.undelegate.prefix);
amino.RegisterConcrete(R_Iris.irisnet.tx.MsgWithdrawDelegatorRewardsAll, Config.iris.tx.withdrawDelegationRewardsAll.prefix);
amino.RegisterConcrete(R_Iris.irisnet.tx.MsgWithdrawDelegatorReward, Config.iris.tx.withdrawDelegationReward.prefix);
amino.RegisterConcrete(R_Iris.irisnet.tx.MsgDeposit, Config.iris.tx.deposit.prefix);
amino.RegisterConcrete(R_Iris.irisnet.tx.MsgVote, Config.iris.tx.vote.prefix);
amino.RegisterConcrete(R_Iris.irisnet.tx.StdTx, Config.iris.tx.stdTx.prefix);
module.exports = amino;
module.exports = amino;
9 changes: 9 additions & 0 deletions src/chains/cosmos/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Old = require('old');
const Bank = require('./bank');
const Stake = require('./stake');
const Distribution = require('./distribution');
const Gov = require('./gov');
const CosmosKeypair = require('./keypair');
const Codec = require("../../util/codec");
const Config = require('../../../config');
Expand Down Expand Up @@ -50,6 +51,14 @@ class CosmosBuilder extends Builder {
msg = Distribution.CreateMsgWithdrawValidatorCommission(req);
break;
}
case Config.cosmos.tx.deposit.type: {
msg = Gov.createMsgDeposit(req);
break;
}
case Config.cosmos.tx.vote.type: {
msg = Gov.createMsgVote(req);
break;
}
default: {
throw new Error("not exist tx type");
}
Expand Down
141 changes: 141 additions & 0 deletions src/chains/cosmos/gov.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
const Config = require('../../../config');
const Root = require('./tx/tx');
const BECH32 = require('bech32');
const Utils = require('../../util/utils');
const Amino = require("../base");

const voteOptionMapping = {
0x00: 'Empty',
0x01: 'Yes',
0x02: 'Abstain',
0x03: 'No',
0x04: 'NoWithVeto'
};

const MsgDeposit = Root.cosmos.MsgDeposit;
MsgDeposit.prototype.type = Config.cosmos.tx.deposit.prefix;
MsgDeposit.prototype.GetSignBytes = function () {
let depositor = BECH32.encode(Config.cosmos.bech32.accAddr, this.depositor);
let signMsg = {
proposal_id: `${this.proposalID}`,
depositor: depositor,
amount: this.amount
};
let sortMsg = Utils.sortObjectKeys(signMsg);
return Amino.MarshalJSON(this.type, sortMsg)
};

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");
}
};

MsgDeposit.prototype.GetMsg = function () {
let depositor = BECH32.fromWords(this.depositor);
return {
proposalID: this.proposalID,
depositor: depositor,
amount: this.amount
}
};

MsgDeposit.prototype.GetDisplayContent = function () {
let depositor = BECH32.encode(Config.cosmos.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.cosmos.bech32.accAddr, this.depositor);
return {
proposal_id: this.proposalID,
depositor: depositor,
amount: this.amount
}
};

const MsgVote = Root.cosmos.MsgVote;
MsgVote.prototype.type = Config.cosmos.tx.vote.prefix;
MsgVote.prototype.GetSignBytes = function () {
let voter = BECH32.encode(Config.cosmos.bech32.accAddr, this.voter);
let signMsg = {
proposal_id: `${this.proposalID}`,
voter: voter,
option: voteOptionMapping[this.option]
};
let sortMsg = Utils.sortObjectKeys(signMsg);
return Amino.MarshalJSON(this.type, sortMsg)
};
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.cosmos.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.cosmos.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
})
}

static createMsgVote(req){
return new MsgVote({
proposalID: `${req.msg.proposal_id}`,
voter: BECH32.decode(req.from).words,
option: req.msg.option
})
}
};
12 changes: 12 additions & 0 deletions src/chains/cosmos/proto/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ message MsgWithdrawValidatorCommission {
required bytes ValidatorAddress = 1;
}

message MsgDeposit {
required int64 proposalID = 1;
required bytes depositor = 2;
repeated Coin amount = 3;
}

message MsgVote {
required int64 proposalID = 1;
required bytes voter = 2;
required uint64 option = 3;
}

message StdFee {
repeated Coin amount = 1;
required int64 gas = 2;
Expand Down
Loading

0 comments on commit 555c87b

Please sign in to comment.