Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,20 +450,43 @@ export class Core {
});
}

public createAssetTransferOutput(params: {
recipient: AssetTransferAddress | string;
assetType: H256 | string;
amount: number;
}): AssetTransferOutput {
const { recipient, assetType, amount } = params;
checkAssetTransferAddressRecipient(recipient);
public createAssetTransferOutput(
params: {
assetType: H256 | string;
amount: number;
} & (
| {
recipient: AssetTransferAddress | string;
}
| {
lockScriptHash: H256 | string;
parameters: Buffer[];
})
): AssetTransferOutput {
const { assetType, amount } = params;
checkAssetType(assetType);
checkAmountU64(amount);
return new AssetTransferOutput({
recipient: AssetTransferAddress.ensure(recipient),
assetType: H256.ensure(assetType),
amount
});
if ("recipient" in params) {
const { recipient } = params;
checkAssetTransferAddressRecipient(recipient);
return new AssetTransferOutput({
recipient: AssetTransferAddress.ensure(recipient),
assetType: H256.ensure(assetType),
amount
});
} else if ("lockScriptHash" in params && "parameters" in params) {
const { lockScriptHash, parameters } = params;
checkLockScriptHash(lockScriptHash);
checkParameters(parameters);
return new AssetTransferOutput({
lockScriptHash: H160.ensure(lockScriptHash),
parameters,
assetType: H256.ensure(assetType),
amount
});
} else {
throw Error(`Unexpected params: ${params}`);
}
}

// FIXME: any
Expand Down