|
@@ -1,8 +1,8 @@
|
|
|
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
|
-import { Option, Vec, Bytes } from '@polkadot/types';
|
|
|
+import { Option, Vec, Bytes, u32 } from '@polkadot/types';
|
|
|
import { Codec } from '@polkadot/types/types';
|
|
|
import { KeyringPair } from '@polkadot/keyring/types';
|
|
|
-import { UserInfo, PaidMembershipTerms } from '@joystream/types/lib/members';
|
|
|
+import { UserInfo, PaidMembershipTerms, MemberId } from '@joystream/types/lib/members';
|
|
|
import { Seat, VoteKind } from '@joystream/types';
|
|
|
import { Balance, EventRecord } from '@polkadot/types/interfaces';
|
|
|
import BN = require('bn.js');
|
|
@@ -41,8 +41,8 @@ export class ApiWrapper {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public getMembership(address: string): Promise<any> {
|
|
|
- return this.api.query.members.memberIdsByControllerAccountId(address);
|
|
|
+ public getMemberIds(address: string): Promise<MemberId[]> {
|
|
|
+ return this.api.query.members.memberIdsByControllerAccountId<Vec<MemberId>>(address);
|
|
|
}
|
|
|
|
|
|
public getBalance(address: string): Promise<Balance> {
|
|
@@ -99,12 +99,51 @@ export class ApiWrapper {
|
|
|
return this.estimateTxFee(this.api.tx.councilElection.reveal(hashedVote, nominee, salt));
|
|
|
}
|
|
|
|
|
|
- public estimateProposeRuntimeUpgradeFee(stake: BN, name: string, description: string, runtime: Bytes): BN {
|
|
|
+ public estimateProposeRuntimeUpgradeFee(stake: BN, name: string, description: string, runtime: Bytes | string): BN {
|
|
|
+ return this.estimateTxFee(
|
|
|
+ this.api.tx.proposalsCodex.createRuntimeUpgradeProposal(stake, name, description, stake, runtime)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public estimateRomeProposeRuntimeUpgradeFee(
|
|
|
+ stake: BN,
|
|
|
+ name: string,
|
|
|
+ description: string,
|
|
|
+ runtime: Bytes | string
|
|
|
+ ): BN {
|
|
|
return this.estimateTxFee(this.api.tx.proposals.createProposal(stake, name, description, runtime));
|
|
|
}
|
|
|
|
|
|
+ public estimateProposeTextFee(stake: BN, name: string, description: string, text: string): BN {
|
|
|
+ return this.estimateTxFee(this.api.tx.proposalsCodex.createTextProposal(stake, name, description, stake, text));
|
|
|
+ }
|
|
|
+
|
|
|
+ public estimateProposeSpendingFee(
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ balance: BN,
|
|
|
+ destination: string
|
|
|
+ ): BN {
|
|
|
+ return this.estimateTxFee(
|
|
|
+ this.api.tx.proposalsCodex.createSpendingProposal(stake, title, description, stake, balance, destination)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public estimateProposeWorkingGroupMintCapacityFee(title: string, description: string, stake: BN, balance: BN): BN {
|
|
|
+ return this.estimateTxFee(
|
|
|
+ this.api.tx.proposalsCodex.createSetContentWorkingGroupMintCapacityProposal(
|
|
|
+ stake,
|
|
|
+ title,
|
|
|
+ description,
|
|
|
+ stake,
|
|
|
+ balance
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
public estimateVoteForProposalFee(): BN {
|
|
|
- return this.estimateTxFee(this.api.tx.proposals.voteOnProposal(0, 'Approve'));
|
|
|
+ return this.estimateTxFee(this.api.tx.proposalsEngine.vote(0, 0, 'Approve'));
|
|
|
}
|
|
|
|
|
|
private applyForCouncilElection(account: KeyringPair, amount: BN): Promise<void> {
|
|
@@ -197,12 +236,27 @@ export class ApiWrapper {
|
|
|
return this.api.query.substrate.code<Bytes>();
|
|
|
}
|
|
|
|
|
|
- public proposeRuntime(
|
|
|
+ public async proposeRuntime(
|
|
|
+ account: KeyringPair,
|
|
|
+ stake: BN,
|
|
|
+ name: string,
|
|
|
+ description: string,
|
|
|
+ runtime: Bytes | string
|
|
|
+ ): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.proposalsCodex.createRuntimeUpgradeProposal(memberId, name, description, stake, runtime),
|
|
|
+ account,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public proposeRuntimeRome(
|
|
|
account: KeyringPair,
|
|
|
stake: BN,
|
|
|
name: string,
|
|
|
description: string,
|
|
|
- runtime: Bytes
|
|
|
+ runtime: Bytes | string
|
|
|
): Promise<void> {
|
|
|
return this.sender.signAndSend(
|
|
|
this.api.tx.proposals.createProposal(stake, name, description, runtime),
|
|
@@ -211,18 +265,83 @@ export class ApiWrapper {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public approveProposal(account: KeyringPair, proposal: BN): Promise<void> {
|
|
|
+ public async proposeText(
|
|
|
+ account: KeyringPair,
|
|
|
+ stake: BN,
|
|
|
+ name: string,
|
|
|
+ description: string,
|
|
|
+ text: string
|
|
|
+ ): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
return this.sender.signAndSend(
|
|
|
- this.api.tx.proposals.voteOnProposal(proposal, new VoteKind('Approve')),
|
|
|
+ this.api.tx.proposalsCodex.createTextProposal(memberId, name, description, stake, text),
|
|
|
+ account,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public async proposeSpending(
|
|
|
+ account: KeyringPair,
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ balance: BN,
|
|
|
+ destination: string
|
|
|
+ ): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.proposalsCodex.createSpendingProposal(memberId, title, description, stake, balance, destination),
|
|
|
+ account,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public async proposeWorkingGroupMintCapacity(
|
|
|
+ account: KeyringPair,
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ balance: BN
|
|
|
+ ): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.proposalsCodex.createSetContentWorkingGroupMintCapacityProposal(
|
|
|
+ memberId,
|
|
|
+ title,
|
|
|
+ description,
|
|
|
+ stake,
|
|
|
+ balance
|
|
|
+ ),
|
|
|
account,
|
|
|
false
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public approveProposal(account: KeyringPair, memberId: BN, proposal: BN): Promise<void> {
|
|
|
+ return this.sender.signAndSend(this.api.tx.proposalsEngine.vote(memberId, proposal, 'Approve'), account, false);
|
|
|
+ }
|
|
|
+
|
|
|
public batchApproveProposal(council: KeyringPair[], proposal: BN): Promise<void[]> {
|
|
|
return Promise.all(
|
|
|
council.map(async keyPair => {
|
|
|
- await this.approveProposal(keyPair, proposal);
|
|
|
+ const memberId: BN = (await this.getMemberIds(keyPair.address))[0].toBn();
|
|
|
+ await this.approveProposal(keyPair, memberId, proposal);
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public approveRomeProposal(account: KeyringPair, proposal: BN): Promise<void> {
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.proposals.voteOnProposal(proposal, new VoteKind('Approve')),
|
|
|
+ account,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public batchApproveRomeProposal(council: KeyringPair[], proposal: BN): Promise<void[]> {
|
|
|
+ return Promise.all(
|
|
|
+ council.map(async keyPair => {
|
|
|
+ await this.approveRomeProposal(keyPair, proposal);
|
|
|
})
|
|
|
);
|
|
|
}
|
|
@@ -254,4 +373,52 @@ export class ApiWrapper {
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ public expectRomeRuntimeUpgraded(): Promise<void> {
|
|
|
+ return new Promise(async resolve => {
|
|
|
+ await this.api.query.system.events<Vec<EventRecord>>(events => {
|
|
|
+ events.forEach(record => {
|
|
|
+ if (record.event.method.toString() === 'RuntimeUpdated') {
|
|
|
+ resolve();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public expectProposalFinalized(): Promise<void> {
|
|
|
+ return new Promise(async resolve => {
|
|
|
+ await this.api.query.system.events<Vec<EventRecord>>(events => {
|
|
|
+ events.forEach(record => {
|
|
|
+ if (
|
|
|
+ record.event.method.toString() === 'ProposalStatusUpdated' &&
|
|
|
+ record.event.data[1].toString().includes('Finalized')
|
|
|
+ ) {
|
|
|
+ resolve();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public getTotalIssuance(): Promise<BN> {
|
|
|
+ return this.api.query.balances.totalIssuance<Balance>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getProposal(id: BN) {
|
|
|
+ const proposal = await this.api.query.proposalsEngine.proposals(id);
|
|
|
+ console.log('proposal to string ' + proposal.toString());
|
|
|
+ console.log('proposal to raw ' + proposal.toRawType());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getRequiredProposalStake(numerator: number, denominator: number): Promise<BN> {
|
|
|
+ const issuance: number = await (await this.getTotalIssuance()).toNumber();
|
|
|
+ const stake = (issuance * numerator) / denominator;
|
|
|
+ return new BN(stake.toFixed(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ public getProposalCount(): Promise<BN> {
|
|
|
+ return this.api.query.proposalsEngine.proposalCount<u32>();
|
|
|
+ }
|
|
|
}
|