From 35662fb5aef65145dbab962a92013fca002020eb Mon Sep 17 00:00:00 2001 From: Nishant Ghodke Date: Tue, 31 Oct 2023 18:28:07 +0530 Subject: [PATCH] refactor: separate types for generator & executor --- packages/sdk/src/brc20/BRC20TransferBase.ts | 11 +++-------- packages/sdk/src/brc20/BRC20TransferExecutor.ts | 4 ++-- packages/sdk/src/brc20/BRC20TransferGenerator.ts | 15 +++------------ 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/packages/sdk/src/brc20/BRC20TransferBase.ts b/packages/sdk/src/brc20/BRC20TransferBase.ts index c04792a6..7e204ada 100644 --- a/packages/sdk/src/brc20/BRC20TransferBase.ts +++ b/packages/sdk/src/brc20/BRC20TransferBase.ts @@ -1,7 +1,7 @@ import { JsonRpcDatasource } from ".." import { Inscriber } from "../transactions/Inscriber" import { - BRC20TransferOptions, + BRC20TransferBaseOptions, GetBRC20BalancesOptions, HasEnoughBalanceOptions, ValidateBRC20TransferOptions @@ -11,15 +11,12 @@ export class BRC20TransferBase extends Inscriber { protected tick: string protected amount = 0 - protected _destinationAddress: string - - constructor({ address, pubKey, destinationAddress, feeRate, network, tick, amount }: BRC20TransferOptions) { + constructor({ address, pubKey, feeRate, network, tick, amount }: BRC20TransferBaseOptions) { super({ - autoAdjustment: false, network, address, changeAddress: address, - destinationAddress: address, // IMPORTANT to keep destination as owner address + destinationAddress: address, publicKey: pubKey, feeRate, postage: 1000, @@ -27,8 +24,6 @@ export class BRC20TransferBase extends Inscriber { mediaContent: "" // Set on payload creation }) - this._destinationAddress = destinationAddress - this.tick = tick this.amount = amount } diff --git a/packages/sdk/src/brc20/BRC20TransferExecutor.ts b/packages/sdk/src/brc20/BRC20TransferExecutor.ts index 0b20e3dd..de88809e 100644 --- a/packages/sdk/src/brc20/BRC20TransferExecutor.ts +++ b/packages/sdk/src/brc20/BRC20TransferExecutor.ts @@ -1,6 +1,6 @@ import { generateTxUniqueIdentifier, Inscription, processInput, PSBTBuilder } from ".." import { BRC20TransferBase } from "./BRC20TransferBase" -import { BRC20TransferOptions, BRC20TransferPayloadAttributes } from "./types" +import { BRC20TransferExecutorOptions, BRC20TransferPayloadAttributes } from "./types" export class BRC20TransferExecutor extends PSBTBuilder { private tick: string @@ -16,7 +16,7 @@ export class BRC20TransferExecutor extends PSBTBuilder { network, tick, amount - }: BRC20TransferOptions) { + }: BRC20TransferExecutorOptions) { super({ address, changeAddress: address, publicKey: pubKey, datasource, feeRate, network, outputs: [] }) this.destinationAddress = destinationAddress diff --git a/packages/sdk/src/brc20/BRC20TransferGenerator.ts b/packages/sdk/src/brc20/BRC20TransferGenerator.ts index a0836cdc..ccda9260 100644 --- a/packages/sdk/src/brc20/BRC20TransferGenerator.ts +++ b/packages/sdk/src/brc20/BRC20TransferGenerator.ts @@ -1,18 +1,9 @@ import { BRC20TransferBase } from "./BRC20TransferBase" -import { BRC20TransferOptions, BRC20TransferPayloadAttributes } from "./types" +import { BRC20TransferBaseOptions, BRC20TransferPayloadAttributes } from "./types" export class BRC20TransferGenerator extends BRC20TransferBase { - constructor({ - address, - pubKey, - datasource, - destinationAddress, - feeRate, - network, - tick, - amount - }: BRC20TransferOptions) { - super({ address, pubKey, datasource, destinationAddress, feeRate, network, tick, amount }) + constructor({ address, pubKey, datasource, feeRate, network, tick, amount }: BRC20TransferBaseOptions) { + super({ address, pubKey, datasource, feeRate, network, tick, amount }) } private async validateTransferOptions() {