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 35662fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 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

0 comments on commit 35662fb

Please sign in to comment.