Skip to content

Commit

Permalink
Check contract is being called from first input.
Browse files Browse the repository at this point in the history
  • Loading branch information
msinkec committed Nov 17, 2023
1 parent 66a530e commit 6d96610
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/contracts/bsv20SellLimitOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
assert,
len,
toByteString,
slice,
int2ByteString,
} from 'scrypt-ts'

/**
Expand Down Expand Up @@ -54,6 +56,12 @@ 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

0 comments on commit 6d96610

Please sign in to comment.