Skip to content

Commit

Permalink
Merge pull request #142 from hangts/master
Browse files Browse the repository at this point in the history
merge brance 'develop'
  • Loading branch information
kaifei Hu authored Feb 18, 2021
2 parents ead4c8b + 2df3592 commit 1c0eb3b
Show file tree
Hide file tree
Showing 55 changed files with 3,660 additions and 3,388 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
"plugins": ["@babel/plugin-proposal-class-properties", "@babel/plugin-transform-runtime"]
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.vscode
docs
docs
.idea/
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@babel/runtime": "^7.0.0",
"@types/mathjs": "^6.0.4",
"@types/ws": "^7.2.2",
"axios": "^0.19.0",
"axios": "^0.21.1",
"bech32": "^1.1.3",
"bip32": "^2.0.4",
"bip39": "^3.0.2",
Expand Down
1 change: 1 addition & 0 deletions dist/src/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export declare class Client {
/** Tx module */
tx: modules.Tx;
/** Gov module */
gov: modules.Gov;
/** Slashing module */
slashing: modules.Slashing;
/** Distribution module */
Expand Down
16 changes: 11 additions & 5 deletions dist/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var Client = /*#__PURE__*/function () {
/** Tx module */

/** Gov module */
// gov: modules.Gov;

/** Slashing module */

Expand Down Expand Up @@ -89,6 +88,7 @@ var Client = /*#__PURE__*/function () {
(0, _defineProperty2["default"])(this, "protobuf", void 0);
(0, _defineProperty2["default"])(this, "staking", void 0);
(0, _defineProperty2["default"])(this, "tx", void 0);
(0, _defineProperty2["default"])(this, "gov", void 0);
(0, _defineProperty2["default"])(this, "slashing", void 0);
(0, _defineProperty2["default"])(this, "distribution", void 0);
(0, _defineProperty2["default"])(this, "utils", void 0);
Expand Down Expand Up @@ -121,8 +121,8 @@ var Client = /*#__PURE__*/function () {
this.keys = new modules.Keys(this);
this.tx = new modules.Tx(this);
this.protobuf = new modules.Protobuf(this);
this.staking = new modules.Staking(this); // this.gov = new modules.Gov(this);

this.staking = new modules.Staking(this);
this.gov = new modules.Gov(this);
this.slashing = new modules.Slashing(this);
this.distribution = new modules.Distribution(this); // this.service = new modules.Service(this);
// this.oracle = new modules.Oracle(this);
Expand Down Expand Up @@ -303,9 +303,15 @@ var DefaultKeyDAOImpl = /*#__PURE__*/function () {
}, {
key: "decrypt",
value: function decrypt(encrptedPrivKey, password) {
var decrypted = AES.decrypt(encrptedPrivKey, password).toString(ENC);
var decrypted;

try {
decrypted = AES.decrypt(encrptedPrivKey, password).toString(ENC);

if (!decrypted) {
if (!decrypted) {
throw new _errors.SdkError('Wrong password', _errors.CODES.InvalidPassword);
}
} catch (e) {
throw new _errors.SdkError('Wrong password', _errors.CODES.InvalidPassword);
}

Expand Down
3 changes: 2 additions & 1 deletion dist/src/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export declare const CODES: {
export declare class SdkError extends Error {
/** Error code */
code: number;
codespace: string;
/**
* Initialize SdkError with irishub error msg
* @param msg irishub error msg
*/
constructor(msg: string, code?: number);
constructor(msg: string, code?: number, space?: string);
}
3 changes: 3 additions & 0 deletions dist/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@ var SdkError = /*#__PURE__*/function (_Error) {
var _this;

var code = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CODES.InvalidRequest;
var space = arguments.length > 2 ? arguments[2] : undefined;
(0, _classCallCheck2["default"])(this, SdkError);
_this = _super.call(this, msg); // const mappedCode = errorMap.get(this.codespace + code);

(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "code", CODES.InvalidRequest);
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "codespace", 'sdk-js');
_this.code = code;
_this.codespace = space !== null && space !== void 0 ? space : _this.codespace;
return _this;
}

Expand Down
4 changes: 2 additions & 2 deletions dist/src/helper/txModelCreator.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as types from '../types';
export declare class TxModelCreator {
static createBodyModel(msgs: types.Msg[], memo: string, timeoutHeight: number): any;
static createAuthInfoModel(fee: types.StdFee, sequence?: string, publicKey?: string | types.Pubkey): any;
static createSignerInfoModel(sequence: string, publicKey: string | types.Pubkey): any;
static createAuthInfoModel(fee: types.StdFee, sequence?: number, publicKey?: string | types.Pubkey): any;
static createSignerInfoModel(sequence: number, publicKey: string | types.Pubkey): any;
static createPublicKeyModel(publicKey: string | types.Pubkey): {
type: string;
value: any;
Expand Down
2 changes: 1 addition & 1 deletion dist/src/helper/txModelCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var TxModelCreator = /*#__PURE__*/function () {
mode_info.setSingle(single);
var signerInfo = new types.tx_tx_pb.SignerInfo();
signerInfo.setModeInfo(mode_info);
signerInfo.setSequence(String(sequence));
signerInfo.setSequence(sequence);

if (publicKey) {
var pk = TxModelCreator.createPublicKeyModel(publicKey);
Expand Down
2 changes: 1 addition & 1 deletion dist/src/modules/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var Auth = /*#__PURE__*/function () {
msgs: msgs,
memo: baseTx.memo || '',
stdFee: stdFee,
chain_id: this.client.config.chainId,
chain_id: baseTx.chainId || this.client.config.chainId,
account_number: baseTx.account_number || undefined,
sequence: baseTx.sequence || undefined
});
Expand Down
141 changes: 48 additions & 93 deletions dist/src/modules/gov.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Client } from '../client';
import * as types from '../types';
import { CommunityTaxUsageType } from '../types/gov';
/**
* This module provides governance functionalities
*
Expand All @@ -15,123 +14,79 @@ export declare class Gov {
/** @hidden */
constructor(client: Client);
/**
* Query details of a single proposal
* @param proposalID Identity of a proposal
* submit Proposal
* @param proposal_id
* @param option
* @param baseTx { types.BaseTx }
* @returns
* @since v0.17
*/
queryProposal(proposalID: number): Promise<types.ProposalResult>;
submitProposal(content: {
type: types.ProposalType;
value: types.TextProposal | types.CommunityPoolSpendProposal | types.ParameterChangeProposal | types.CancelSoftwareUpgradeProposal | types.SoftwareUpgradeProposal;
}, initial_deposit: types.Coin[], baseTx: types.BaseTx): Promise<types.TxResult>;
/**
* Query proposals by conditions
* @param params
* vote
* @param proposal_id
* @param option
* @param baseTx { types.BaseTx }
* @returns
* @since v0.17
*/
queryProposals(params?: types.QueryProposalsParams): Promise<types.ProposalResult[]>;
vote(proposal_id: number, option: types.VoteOption, baseTx: types.BaseTx): Promise<types.TxResult>;
/**
* Query a vote
* @param proposalID Identity of a proposal
* @param voter Bech32 voter address
* deposit
* @param proposal_id
* @param amount
* @param baseTx { types.BaseTx }
* @returns
* @since v0.17
*/
queryVote(proposalID: number, voter: string): Promise<types.VoteResult>;
deposit(proposal_id: number, amount: types.Coin[], baseTx: types.BaseTx): Promise<types.TxResult>;
/**
* Query all votes of a proposal
* @param proposalID Identity of a proposal
* @returns
* @since v0.17
* Proposal queries proposal details based on ProposalID.
* @param proposal_id defines the unique id of the proposal.
*/
queryVotes(proposalID: number): Promise<types.VoteResult[]>;
queryProposal(proposal_id: number): Promise<object>;
/**
* Query a deposit of a proposal
* @param proposalID Identity of a proposal
* @param depositor Bech32 depositor address
* @returns
* @since v0.17
* Proposals queries all proposals based on given status.
* @param proposal_id defines the unique id of the proposal.
*/
queryDeposit(proposalID: number, depositor: string): Promise<types.VoteResult>;
queryProposals(option: {
proposal_status?: types.ProposalStatus;
voter?: string;
depositor?: string;
}, page_number?: number, page_size?: number): Promise<object>;
/**
* Query all deposits of a proposal
* @param proposalID Identity of a proposal
* @returns
* @since v0.17
*/
queryDeposits(proposalID: number): Promise<types.VoteResult>;
/**
* Query the statistics of a proposal
* @param proposalID Identity of a proposal
* @returns
* @since v0.17
* Vote queries voted information based on proposalID, voterAddr.
* @param proposal_id defines the unique id of the proposal.
* @param voter defines the oter address for the proposals.
*/
queryTally(proposalID: number): Promise<types.TallyResult>;
queryVote(proposal_id: number, voter: string): Promise<object>;
/**
* Submit a ParameterChangeProposal along with an initial deposit
*
* The proposer must deposit at least 30% of the [MinDeposit](https://www.irisnet.org/docs/features/governance.html#proposal-level) to submit a proposal.
*
* [Read about which parameters can be changed online](https://www.irisnet.org/docs/concepts/gov-params.html)
*
* @param title Title of the proposal
* @param description Description of the proposal
* @param initialDeposit Initial deposit of the proposal(at least 30% of minDeposit)
* @param params On-chain Parameter to be changed, eg. `[{"subspace":"mint","key":"Inflation","value":"0.05"}]`
* @param baseTx
* @returns
* @since v0.17
* Votes queries votes of a given proposal.
* @param proposal_id defines the unique id of the proposal.
*/
submitParameterChangeProposal(title: string, description: string, initialDeposit: types.Coin[], params: types.ChangeParameter[], baseTx: types.BaseTx): Promise<types.TxResult>;
queryVotes(proposal_id: number, page_number?: number, page_size?: number): Promise<object>;
/**
* Submit a PlainTextProposal along with an initial deposit
*
* The proposer must deposit at least 30% of the [MinDeposit](https://www.irisnet.org/docs/features/governance.html#proposal-level) to submit a proposal.
*
* @param title Title of the proposal
* @param description Description of the proposal
* @param initialDeposit Initial deposit of the proposal(at least 30% of minDeposit)
* @param baseTx
* @returns
* @since v0.17
* Params queries all parameters of the gov module.
* @param params_type defines which parameters to query for, can be one of "voting", "tallying" or "deposit".
*/
submitPlainTextProposal(title: string, description: string, initialDeposit: types.Coin[], baseTx: types.BaseTx): Promise<types.TxResult>;
queryParams(params_type: string): Promise<object>;
/**
* Submit a CommunityTaxUsageProposal along with an initial deposit
*
* There are three usages, Burn, Distribute and Grant. Burn means burning tokens from community funds.
* Distribute and Grant will transfer tokens to the destination trustee's account from community funds.
*
* The proposer must deposit at least 30% of the [MinDeposit](https://www.irisnet.org/docs/features/governance.html#proposal-level) to submit a proposal.
*
* @param title Title of the proposal
* @param description Description of the proposal
* @param initialDeposit Initial deposit of the proposal(at least 30% of minDeposit)
* @param usage Type of the CommunityTaxUsage
* @param dest_address Bech32 destination address to receive the distributed or granted funds
* @param percent Percentage of the current community pool to be used
* @param baseTx
* @since v0.17
* Deposit queries single deposit information based proposalID, depositAddr.
* @param proposal_id defines the unique id of the proposal.
* @param depositor defines the deposit addresses from the proposals.
*/
submitCommunityTaxUsageProposal(title: string, description: string, initialDeposit: types.Coin[], usage: CommunityTaxUsageType, destAddress: string, percent: number, baseTx: types.BaseTx): Promise<types.TxResult>;
queryDeposit(proposal_id: number, depositor: string): Promise<object>;
/**
* Deposit tokens for an active proposal.
*
* When the total deposit amount exceeds the [MinDeposit](https://www.irisnet.org/docs/features/governance.html#proposal-level), the proposal will enter the voting procedure.
*
* @param proposalID Identity of a proposal
* @param amount Amount to be deposited
* @param baseTx
* @returns
* @since v0.17
* Deposits queries all deposits of a single proposal.
* @param proposal_id defines the unique id of the proposal.
*/
deposit(proposalID: number, amount: types.Coin[], baseTx: types.BaseTx): Promise<types.TxResult>;
queryDeposits(proposal_id: number, page_number?: number, page_size?: number): Promise<object>;
/**
* Vote for an active proposal, options: Yes/No/NoWithVeto/Abstain.
* Only validators and delegators can vote for proposals in the voting period.
*
* @param proposalID Identity of a proposal
* @param option Vote option
* @param baseTx
* @since v0.17
* TallyResult queries the tally of a proposal vote.
* @param proposal_id defines the unique id of the proposal.
*/
vote(proposalID: number, option: types.VoteOption, baseTx: types.BaseTx): Promise<types.TxResult>;
queryTallyResult(proposal_id: number): Promise<object>;
}
Loading

0 comments on commit 1c0eb3b

Please sign in to comment.