Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
gitzhou committed Mar 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a5f671f commit f1cbfde
Showing 2 changed files with 15 additions and 29 deletions.
34 changes: 10 additions & 24 deletions src/contracts/oracleDemoBsv20.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import {
assert,
method,
prop,
reverseByteString,
slice,
} from 'scrypt-ts'
import { RabinPubKey, RabinSig, WitnessOnChainVerifier } from 'scrypt-ts-lib'
@@ -14,9 +13,8 @@ type Msg = {
marker: bigint // 1 byte, api marker
timestamp: bigint // 4 bytes LE
network: bigint // 1 byte, 1 for mainnet, 0 for testnet
txid: ByteString // 32 bytes, txid
vout: bigint // 4 bytes LE, output index
bsv20: bigint // 1 byte, token type, 0 for NFT, 1 for BSV20
outpoint: ByteString // 36 bytes, txid 32 bytes LE + vout 4 bytes LE
fungible: bigint // 1 byte, token type, 1 for BSV20, 0 for NFT
amt: bigint // 8 bytes LE
id: ByteString
}
@@ -47,9 +45,8 @@ export class OracleDemoBsv20 extends SmartContract {
marker: Utils.fromLEUnsigned(slice(msg, 0n, 1n)),
timestamp: Utils.fromLEUnsigned(slice(msg, 1n, 5n)),
network: Utils.fromLEUnsigned(slice(msg, 5n, 6n)),
txid: slice(msg, 6n, 38n),
vout: Utils.fromLEUnsigned(slice(msg, 38n, 42n)),
bsv20: Utils.fromLEUnsigned(slice(msg, 42n, 43n)),
outpoint: slice(msg, 6n, 42n),
fungible: Utils.fromLEUnsigned(slice(msg, 42n, 43n)),
amt: Utils.fromLEUnsigned(slice(msg, 43n, 51n)),
id: slice(msg, 51n),
}
@@ -58,20 +55,10 @@ export class OracleDemoBsv20 extends SmartContract {
@method()
public unlock(msg: ByteString, sig: RabinSig, tokenInputIndex: bigint) {
// retrieve token outpoint from prevouts
const txid = reverseByteString(
slice(
this.prevouts,
tokenInputIndex * 36n,
tokenInputIndex * 36n + 32n
),
32n
)
const vout = Utils.fromLEUnsigned(
slice(
this.prevouts,
tokenInputIndex * 36n + 32n,
tokenInputIndex * 36n + 36n
)
const outpoint = slice(
this.prevouts,
tokenInputIndex * 36n,
(tokenInputIndex + 1n) * 36n
)
// verify oracle signature
assert(
@@ -83,9 +70,8 @@ export class OracleDemoBsv20 extends SmartContract {
// validate data
assert(message.marker == 4n, 'incorrect oracle message type')
assert(message.network == 0n, 'incorrect network')
assert(message.txid == txid, 'incorrect token txid')
assert(message.vout == vout, 'incorrect token vout')
assert(message.bsv20 == 1n, 'incorrect token type')
assert(message.outpoint == outpoint, 'incorrect token outpoint')
assert(message.fungible == 1n, 'incorrect token type')
assert(message.amt >= this.amt, 'incorrect token amount')
assert(message.id == this.inscriptionId, 'incorrect inscription id')
// do other validations ...
10 changes: 5 additions & 5 deletions tests/oracleDemoBsv20.test.ts
Original file line number Diff line number Diff line change
@@ -24,16 +24,16 @@ const PUBKEY = {
}
// https://api.witnessonchain.com/#/v1/V1Controller_getInscription
const RESP = {
timestamp: 1711167431,
timestamp: 1711511226,
outpoint:
'7972d872ae5cbd4fe1dd5912a7cef79745950bce38ba6f1df912ee1fe5952557_0',
bsv20: true,
fungible: 1,
amt: 10000,
id: '7972d872ae5cbd4fe1dd5912a7cef79745950bce38ba6f1df912ee1fe5952557_0',
data: '04c757fe65007972d872ae5cbd4fe1dd5912a7cef79745950bce38ba6f1df912ee1fe595255700000000011027000000000000373937326438373261653563626434666531646435393132613763656637393734353935306263653338626136663164663931326565316665353935323535375f30',
data: '04ba96036600572595e51fee12f91d6fba38ce0b954597f7cea71259dde14fbd5cae72d8727900000000011027000000000000373937326438373261653563626434666531646435393132613763656637393734353935306263653338626136663164663931326565316665353935323535375f30',
signature: {
s: '3b8f6fc2981eac44d8284b149e14acfd98a2b2c104e32c184cb01e1c6206160a2e767488db1754d84842ab664d3027147d2123875a380dd901b736b77db6a279a6f513f2b3ad2daecd44ea54ff920cb99c52da395315c018ba92b0e5e767bbdd5d64249cf535dcada6c8a01b45233f406892604945a29af3e2be8b62ed1f7d7b4415ce7f1081da64aee51eec3464b7a558ac689a834a2d9f31ecac29647221c2d9a757845e5cb621cf2c5c6e8005c4ecb18c98cb4ba30d5850c403e22e42edb064cbf43d7f20d21febc2c36480e2e7ae1a7ef14567f0e4f794600a8004d25729b96cee269409d86ed725c8380db54cc936b46c4512839287bdc3be9226f8b5378e15443761d0d4c33ba94fac1b6175ab57d82861adb88041d8a6635dcca82c1691cd600498681a8f0eaf1c8ceaf4a000edf35a5c6baed5534c43a614138cec9ddcbb2948760cd6f63c7c749bd63788e5eb530ef4461da6f6e9ca46eae374daa7f36dab316e57910e5256c09ff674bd8ad20ab06a98a014f891e7cc17da764806',
padding: '00',
s: '80385ea550a64558f7d0146c7b7485b36044b20e2e291cb089864c80d344476657c291688c6459ce7037cb2ee8941c1b6176a2b9e46da429ba91564daadd72f2d5b2b9550cd0a9a78df8eda96905848fec8bfbf600dd2af2cd336b7b6d0615fe1e3ce41b7de3498fe0e0cd6e86d79c62199eea2eb514663ba8fabc3eaf6a603487c10465650b20c48b87fb5d0a1f913073f90eb2b0e9f56eb41b5518f76b8bb2cd7906c5bb0855d6f0a6fe5e6456c8a27e5868f36374733043e4cc0c6dd28e5e4cd0bdb3b7b76dbcfee5a7cfe4fc87404aa431058ef58dcf528ad0a37fc5f8ede5da557bdd0e4fc5007e4e2b502199fd794785e67e534c213ca73b0bb02bebc822cfe97b5fcbaebb45ebd875499e923b10af2d05db8ec5220afad9dd45eef04569ddb8f6bbf0e6cf53407387c87358b9ebdce084930239de1efdc130df4b05814ee22a8848436ce94b2b4d87643e0d24dd9d155dcd750f726f893763d56c530d57480a207c50ea7f165c9e33909354f340ceab752eac60d52dcc653a5ca0e23f',
padding: '0000000000000000',
},
}

0 comments on commit f1cbfde

Please sign in to comment.