Created
July 22, 2020 10:48
-
-
Save corbifex/1dd65ee6344e83c2f00dfb6ae8246ff8 to your computer and use it in GitHub Desktop.
Add Member proposal custom apply phase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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