Skip to content

Commit

Permalink
Rm first input check, fix payment to seller.
Browse files Browse the repository at this point in the history
  • Loading branch information
msinkec committed Nov 18, 2023
1 parent 6d96610 commit 0c86ec3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/contracts/bsv20SellLimitOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
toByteString,
slice,
int2ByteString,
hash160,
} from 'scrypt-ts'

/**
Expand Down Expand Up @@ -56,12 +57,6 @@ export class BSV20SellLimitOrder extends BSV20V2 {

@method()
public buy(amount: bigint, buyerAddr: Addr) {
// Ensure the contract is being called via the first input of the call tx.
const outpoint: ByteString =
this.ctx.utxo.outpoint.txid +
int2ByteString(this.ctx.utxo.outpoint.outputIndex, 4n)
assert(outpoint == slice(this.prevouts, 0n, 36n))

// Check token amount doesn't exceed total.
assert(
this.tokenAmtSold + amount < this.tokenAmt,
Expand Down Expand Up @@ -93,9 +88,12 @@ export class BSV20SellLimitOrder extends BSV20V2 {
amount
)

// Ensure the next output is paying the to the Bitcoin to the buyer.
const satsForBuyer = this.pricePerUnit * amount
outputs += Utils.buildPublicKeyHashOutput(buyerAddr, satsForBuyer)
// Ensure the next output is paying the to the Bitcoin to the seller.
const satsForSeller = this.pricePerUnit * amount
outputs += Utils.buildPublicKeyHashOutput(
hash160(this.seller),
satsForSeller
)

// Add change output.
outputs += this.buildChangeOutput()
Expand Down

0 comments on commit 0c86ec3

Please sign in to comment.