From 370c09f214cd858702dd93f6b2cefc623c5a0b83 Mon Sep 17 00:00:00 2001 From: JinGyeong Jeong Date: Tue, 16 Oct 2018 15:43:09 +0900 Subject: [PATCH] Make createAssetTransferOutput() support lockScriptHash and parameters params --- src/core/index.ts | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/core/index.ts b/src/core/index.ts index ca70224e..56a5f983 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -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