generated from PolymeshAssociation/typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
555119e
commit 72369e7
Showing
3 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { assertPortfolioExists } from '~/api/procedures/utils'; | ||
import { DefaultPortfolio, NumberedPortfolio, PolymeshError, Procedure } from '~/internal'; | ||
import { ErrorCode, RoleType, TxTags } from '~/types'; | ||
import { PortfolioId, ProcedureAuthorization } from '~/types/internal'; | ||
import { portfolioIdToMeshPortfolioId, portfolioLikeToPortfolioId } from '~/utils/conversion'; | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
export type Params = { | ||
portfolio: DefaultPortfolio | NumberedPortfolio; | ||
}; | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
export async function prepareQuitCustody( | ||
this: Procedure<Params, void>, | ||
args: Params | ||
): Promise<void> { | ||
const { | ||
context: { | ||
polymeshApi: { tx }, | ||
}, | ||
context, | ||
} = this; | ||
|
||
const { portfolio } = args; | ||
|
||
const { | ||
owner: { did }, | ||
} = portfolio; | ||
|
||
const { did: currentDid } = await context.getCurrentIdentity(); | ||
|
||
if (currentDid === did) { | ||
throw new PolymeshError({ | ||
code: ErrorCode.ValidationError, | ||
message: 'The Portfolio Custodian is the Current Identity', | ||
}); | ||
} | ||
|
||
const portfolioId = portfolioLikeToPortfolioId(portfolio); | ||
|
||
await assertPortfolioExists(portfolioId, context); | ||
|
||
const rawPortfolioId = portfolioIdToMeshPortfolioId(portfolioId, context); | ||
|
||
this.addTransaction(tx.portfolio.quitPortfolioCustody, {}, rawPortfolioId); | ||
} | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
export function getAuthorization( | ||
this: Procedure<Params>, | ||
{ portfolio }: Params | ||
): ProcedureAuthorization { | ||
const { | ||
owner: { did }, | ||
} = portfolio; | ||
let portfolioId: PortfolioId = { did }; | ||
|
||
if (portfolio instanceof NumberedPortfolio) { | ||
portfolioId = { ...portfolioId, number: portfolio.id }; | ||
} | ||
|
||
return { | ||
signerPermissions: { | ||
transactions: [TxTags.portfolio.QuitPortfolioCustody], | ||
tokens: [], | ||
portfolios: [portfolio], | ||
}, | ||
identityRoles: [{ type: RoleType.PortfolioCustodian, portfolioId }], | ||
}; | ||
} | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
export const quitCustody = (): Procedure<Params, void> => | ||
new Procedure(prepareQuitCustody, getAuthorization); |
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