Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parseError(error: any) {
if (error instanceof ProviderError) {
return error;
} else if (Object.values(ProviderIssue).includes(error)) {
return new ProviderError(error);
} else {
return new ProviderError(ProviderIssue.CONTRACT_ERROR, error);
}
}
public async approveValue(value: string, accountId: string): Promise {
accountId = this._provider.encoder.normalizeAddress(accountId as string);
const approvedValue = await this.getApprovedValue(this.provider.accountId, accountId);
if (!bigNumberify(value).isZero() && !bigNumberify(approvedValue).isZero()) {
throw new ProviderError(ProviderIssue.ERC20_APPROVAL_RACE_CONDITION);
}
return approveAccount(this, accountId, value);
}
export function parseError(error: any) {
if (error instanceof ProviderError) {
return error;
} else if (Object.values(ProviderIssue).includes(error)) {
return new ProviderError(error);
} else {
return new ProviderError(ProviderIssue.CONTRACT_ERROR, error);
}
}
if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {
return ProxyId.TOKEN_TRANSFER;
} else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
return gateway.provider.unsafeRecipientIds.indexOf(action.ledgerId) === -1
? ProxyId.NFTOKEN_SAFE_TRANSFER
: ProxyId.NFTOKEN_TRANSFER;
} else if (action.kind == ActionsOrderActionKind.CREATE_ASSET) {
return ProxyId.XCERT_CREATE;
} else if (action.kind == ActionsOrderActionKind.SET_ABILITIES) {
return ProxyId.MANAGE_ABILITIES;
} else if (action.kind == ActionsOrderActionKind.UPDATE_ASSET_IMPRINT) {
return ProxyId.XCERT_UPDATE;
} else if (action.kind == ActionsOrderActionKind.DESTROY_ASSET) {
return ProxyId.XCERT_BURN;
} else {
throw new ProviderError(ProviderIssue.WRONG_INPUT, 'Not implemented.');
}
}
export function getActionParams(action: ActionsOrderAction, signers: string[]) {
let params = '';
const signerIndex = signers.indexOf(action['senderId']);
if (signerIndex === -1) {
throw new ProviderError(ProviderIssue.WRONG_INPUT, 'SenderId not a signer.');
}
if (action.kind == ActionsOrderActionKind.CREATE_ASSET) {
params = rightPad(`0x${action['assetImprint']}`, 64);
params += leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', false);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.SET_ABILITIES) {
const bitAbilities = getBitfieldFromAbilities(action.abilities);
params = leftPad(bitAbilities, 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_ASSET) {
params = leftPad(bigNumberify(action['assetId']).toHexString(), 64, '0', true);
params += action['receiverId'].substr(2);
params += leftPad(bigNumberify(signerIndex).toHexString(), 2, '0', false);
} else if (action.kind == ActionsOrderActionKind.TRANSFER_VALUE) {