Skip to content

Instantly share code, notes, and snippets.

@corbifex
Created July 22, 2020 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corbifex/1dd65ee6344e83c2f00dfb6ae8246ff8 to your computer and use it in GitHub Desktop.
Save corbifex/1dd65ee6344e83c2f00dfb6ae8246ff8 to your computer and use it in GitHub Desktop.
Add Member proposal custom apply phase
public async applyProposalAsset(store: StateStore): Promise<ApplyProposal> {
const errors: TransactionError[] = [];
const proposal = await store.account.getOrDefault(this.getProposalAddress()) as ProposalAccount;
const addressBook = await store.account.getOrDefault(getAddressFromPublicKey(this.asset.addressBook)) as AddressBookAccount;
const proposedMember = await store.account.getOrDefault(getAddressFromPublicKey(this.asset.options.member)) as Account;
if (!this.asset.options.member) {
errors.push(
new TransactionError(
'`.asset.options.member` should contain the proposal.',
this.id,
'.asset.options.member',
undefined,
),
);
}
if (addressBook.asset.addresses.find(m => m === this.asset.options.member)) {
errors.push(
new TransactionError(
'`.asset.options.member` already is in this address book.',
this.id,
'.asset.options.member',
this.asset.options.member,
),
);
}
if (proposedMember.publicKey === undefined) {
errors.push(
new TransactionError(
'`.asset.options.member` not found on the blockchain.',
this.id,
'.asset.options.member',
this.asset.options.member,
'not found'
),
);
}
proposal.asset = {
...proposal.asset,
type: "ADD_MEMBER",
options: {
member: this.asset.options.member ? this.asset.options.member : "",
},
}
return { proposal, errors };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment