From 6d966107ffa565578ead1f2ccb9d5f5c9a449331 Mon Sep 17 00:00:00 2001 From: msinkec Date: Fri, 17 Nov 2023 09:30:35 +0100 Subject: [PATCH] Check contract is being called from first input. --- src/contracts/bsv20SellLimitOrder.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/contracts/bsv20SellLimitOrder.ts b/src/contracts/bsv20SellLimitOrder.ts index b9586efe..b1fbf6b2 100644 --- a/src/contracts/bsv20SellLimitOrder.ts +++ b/src/contracts/bsv20SellLimitOrder.ts @@ -12,6 +12,8 @@ import { assert, len, toByteString, + slice, + int2ByteString, } from 'scrypt-ts' /** @@ -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,