Skip to content

Commit

Permalink
refactor: separate types for generator & executor
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcrazycoder committed Oct 31, 2023
1 parent 3d7f891 commit 1c1113f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
11 changes: 3 additions & 8 deletions packages/sdk/src/brc20/BRC20TransferBase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JsonRpcDatasource } from ".."
import { Inscriber } from "../transactions/Inscriber"
import {
BRC20TransferOptions,
BRC20TransferBaseOptions,
GetBRC20BalancesOptions,
HasEnoughBalanceOptions,
ValidateBRC20TransferOptions
Expand All @@ -11,24 +11,19 @@ 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,
mediaType: "<temp-type>", // Set on payload creation
mediaContent: "<temp-content>" // Set on payload creation
})

this._destinationAddress = destinationAddress

this.tick = tick
this.amount = amount
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/brc20/BRC20TransferExecutor.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
15 changes: 3 additions & 12 deletions packages/sdk/src/brc20/BRC20TransferGenerator.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
17 changes: 13 additions & 4 deletions packages/sdk/src/brc20/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,9 +79,9 @@ export interface BRC20TokenAttributes {
timestamp: number
}

export type ValidateBRC20TransferOptions = Pick<BRC20TransferOptions, "amount" | "datasource" | "tick" | "network">
export type GetBRC20BalancesOptions = Pick<BRC20TransferOptions, "address" | "datasource" | "tick" | "network">
export type ValidateBRC20TransferOptions = Pick<BRC20TransferBaseOptions, "amount" | "datasource" | "tick" | "network">
export type GetBRC20BalancesOptions = Pick<BRC20TransferBaseOptions, "address" | "datasource" | "tick" | "network">
export type HasEnoughBalanceOptions = Pick<
BRC20TransferOptions,
BRC20TransferBaseOptions,
"address" | "amount" | "datasource" | "tick" | "network"
>

0 comments on commit 1c1113f

Please sign in to comment.