From 1c1113f3bf9e5803d5a06700329f659b82558f5b 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 ++-- .../sdk/src/brc20/BRC20TransferGenerator.ts | 15 +++------------ packages/sdk/src/brc20/types.ts | 17 +++++++++++++---- 4 files changed, 21 insertions(+), 26 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() { diff --git a/packages/sdk/src/brc20/types.ts b/packages/sdk/src/brc20/types.ts index 5272e4a8..0708787e 100644 --- a/packages/sdk/src/brc20/types.ts +++ b/packages/sdk/src/brc20/types.ts @@ -25,7 +25,16 @@ export type BRC20MintOptions = BRC20Options<{ amount: number }> -export type BRC20TransferOptions = BRC20Options<{ +export type BRC20TransferBaseOptions = BRC20Options<{ + address: string + pubKey: string + tick: string + amount: number +}> + +export type BRC20TransferGeneratorOptions = BRC20TransferBaseOptions + +export type BRC20TransferExecutorOptions = BRC20Options<{ address: string pubKey: string destinationAddress: string @@ -70,9 +79,9 @@ export interface BRC20TokenAttributes { timestamp: number } -export type ValidateBRC20TransferOptions = Pick -export type GetBRC20BalancesOptions = Pick +export type ValidateBRC20TransferOptions = Pick +export type GetBRC20BalancesOptions = Pick export type HasEnoughBalanceOptions = Pick< - BRC20TransferOptions, + BRC20TransferBaseOptions, "address" | "amount" | "datasource" | "tick" | "network" >