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 normalizeOrderIds(order: ValueLedgerDeployOrder, provider: GenericProvider): ValueLedgerDeployOrder {
order = JSON.parse(JSON.stringify(order));
let dynamic = false;
if (!order.takerId) {
order.takerId = zeroAddress;
dynamic = true;
} else {
order.takerId = provider.encoder.normalizeAddress(order.takerId);
}
order.makerId = provider.encoder.normalizeAddress(order.makerId);
order.tokenTransferData.ledgerId = provider.encoder.normalizeAddress(order.tokenTransferData.ledgerId);
if (!order.tokenTransferData.receiverId) {
if (!dynamic) {
throw new ProviderError(ProviderIssue.WRONG_INPUT, 'receiverId is not set.');
}
order.tokenTransferData.receiverId = zeroAddress;
} else {
order.tokenTransferData.receiverId = provider.encoder.normalizeAddress(order.tokenTransferData.receiverId);
}
order.valueLedgerData.ownerId = provider.encoder.normalizeAddress(order.valueLedgerData.ownerId);
return order;
}
export function normalizeOrderIds(order: AssetLedgerDeployOrder, provider: GenericProvider): AssetLedgerDeployOrder {
order = JSON.parse(JSON.stringify(order));
let dynamic = false;
if (!order.takerId) {
order.takerId = zeroAddress;
dynamic = true;
} else {
order.takerId = provider.encoder.normalizeAddress(order.takerId);
}
order.makerId = provider.encoder.normalizeAddress(order.makerId);
order.tokenTransferData.ledgerId = provider.encoder.normalizeAddress(order.tokenTransferData.ledgerId);
if (!order.tokenTransferData.receiverId) {
if (!dynamic) {
throw new ProviderError(ProviderIssue.WRONG_INPUT, 'receiverId is not set.');
}
order.tokenTransferData.receiverId = zeroAddress;
} else {
order.tokenTransferData.receiverId = provider.encoder.normalizeAddress(order.tokenTransferData.receiverId);
}
order.assetLedgerData.ownerId = provider.encoder.normalizeAddress(order.assetLedgerData.ownerId);
return order;
}
order.actions.forEach((action) => {
action.ledgerId = provider.encoder.normalizeAddress(action.ledgerId);
action['senderId'] = action['senderId'] ? provider.encoder.normalizeAddress(action['senderId']) : action['senderId'] = ZERO_ADDRESS;
if (action.kind !== ActionsOrderActionKind.UPDATE_ASSET_IMPRINT && action.kind !== ActionsOrderActionKind.DESTROY_ASSET) {
action['receiverId'] = action['receiverId'] ? provider.encoder.normalizeAddress(action['receiverId']) : action['receiverId'] = ZERO_ADDRESS;
if (action['senderId'] === ZERO_ADDRESS && action['receiverId'] === ZERO_ADDRESS) {
throw new ProviderError(ProviderIssue.WRONG_INPUT, 'Both senderId and receiverId missing.');
}
}
});
}
export function normalizeDeployIds(deploy: Deploy, provider: GenericProvider): Deploy {
deploy = JSON.parse(JSON.stringify(deploy));
let dynamic = false;
if (!deploy.takerId) {
deploy.takerId = zeroAddress;
dynamic = true;
} else {
deploy.takerId = provider.encoder.normalizeAddress(deploy.takerId);
}
deploy.makerId = provider.encoder.normalizeAddress(deploy.makerId);
deploy.tokenTransferData.ledgerId = provider.encoder.normalizeAddress(deploy.tokenTransferData.ledgerId);
if (!deploy.tokenTransferData.receiverId) {
if (!dynamic) {
throw new ProviderError(ProviderIssue.WRONG_INPUT, 'receiverId is not set.');
}
deploy.tokenTransferData.receiverId = zeroAddress;
} else {
deploy.tokenTransferData.receiverId = provider.encoder.normalizeAddress(deploy.tokenTransferData.receiverId);
}
deploy.assetLedgerData.owner = provider.encoder.normalizeAddress(deploy.assetLedgerData.owner);
return deploy;
}