Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.