diff --git a/.gitignore b/.gitignore index 70a1fab..c251327 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ node_modules/ -# dist/ +dist/ out/ -# artifacts/ +artifacts/ **/.env -# **/scrypt.index.json +**/scrypt.index.json .vscode/* !.vscode/launch.json !.vscode/tasks.json diff --git a/artifacts/src/contracts/ordinal-lock.json b/artifacts/src/contracts/ordinal-lock.json deleted file mode 100644 index ba86739..0000000 --- a/artifacts/src/contracts/ordinal-lock.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "version": 9, - "compilerVersion": "1.19.0+commit.72eaeba", - "contract": "OrdinalLock", - "md5": "5a1757e1bb8309ab7c73020aee538003", - "structs": [], - "library": [], - "alias": [], - "abi": [ - { - "type": "function", - "name": "purchase", - "index": 0, - "params": [ - { - "name": "selfOutput", - "type": "bytes" - }, - { - "name": "trailingOutputs", - "type": "bytes" - }, - { - "name": "__scrypt_ts_txPreimage", - "type": "SigHashPreimage" - } - ] - }, - { - "type": "function", - "name": "cancel", - "index": 1, - "params": [ - { - "name": "sig", - "type": "Sig" - }, - { - "name": "pubkey", - "type": "PubKey" - } - ] - }, - { - "type": "constructor", - "params": [ - { - "name": "seller", - "type": "Ripemd160" - }, - { - "name": "payOutput", - "type": "bytes" - } - ] - } - ], - "stateProps": [], - "buildType": "debug", - "file": "file:///Users/davidcase/Source/ordinals/ordinal-lock/artifacts/src/contracts/ordinal-lock.scrypt", - "hex": "2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000615179547a75537a537a537a0079537a75527a527a7575615579008763567901c161517957795779210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081059795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169587951797e58797eaa577961007982775179517958947f7551790128947f77517a75517a75618777777777777777777767557951876351795779a9876957795779ac777777777777777767006868", - "sourceMapFile": "file:///var/folders/2v/014041p126bgrcjspgbn0tgw0000gn/T/scrypt-ts-UeM3Oe/ordinal-lock.map.json" -} \ No newline at end of file diff --git a/artifacts/src/contracts/ordinal-lock.scrypt b/artifacts/src/contracts/ordinal-lock.scrypt deleted file mode 100644 index 6c7d150..0000000 --- a/artifacts/src/contracts/ordinal-lock.scrypt +++ /dev/null @@ -1,17 +0,0 @@ - -contract OrdinalLock { - Ripemd160 seller; - bytes payOutput; - constructor(Ripemd160 seller, bytes payOutput) { - this.seller = seller; - this.payOutput = payOutput; - } - public function purchase(bytes selfOutput, bytes trailingOutputs, SigHashPreimage __scrypt_ts_txPreimage) { - require(Tx.checkPreimageSigHashType(__scrypt_ts_txPreimage, SigHashType(b'c1'))); - require(hash256(selfOutput + this.payOutput + trailingOutputs) == SigHash.hashOutputs(__scrypt_ts_txPreimage)); - } - public function cancel(Sig sig, PubKey pubkey) { - require(this.seller == hash160(pubkey)); - require(checkSig(sig, pubkey)); - } -} \ No newline at end of file diff --git a/artifacts/src/contracts/ordinal-lock.scrypt.map b/artifacts/src/contracts/ordinal-lock.scrypt.map deleted file mode 100644 index fca404f..0000000 --- a/artifacts/src/contracts/ordinal-lock.scrypt.map +++ /dev/null @@ -1 +0,0 @@ -[[],[[9,0,14,13]],[[2,0,16,12],[12,0,16,4]],[[2,0,19,15],[8,0,19,4]],[[2,0,21,4],[14,0,21,24],[24,0,21,16],[32,0,21,47],[38,0,21,36]],[[4,0,24,8],[8,0,24,13],[16,0,24,8],[18,0,24,22]],[[4,0,25,8],[8,0,25,13],[19,0,25,8],[21,0,25,25]],[],[[2,0,29,4],[18,0,29,11],[27,0,29,32],[33,0,29,20],[45,0,29,61],[51,0,29,44]],[],[[4,0,30,8],[12,0,30,15],[20,0,30,23],[31,0,30,23],[33,0,30,36],[37,0,30,41],[48,0,30,23],[50,0,30,53],[67,0,30,15],[77,0,30,82]],[],[[2,0,34,4],[18,0,34,11],[25,0,34,23],[29,0,34,18],[34,0,34,36],[41,0,34,28]],[[4,0,35,8],[12,0,35,15],[16,0,35,20],[24,0,35,15],[27,0,35,30],[35,0,35,38]],[[4,0,36,8],[12,0,36,20],[20,0,36,15],[21,0,36,29],[26,0,36,34],[32,0,36,15]],[],[]] \ No newline at end of file diff --git a/artifacts/src/contracts/ordinal-lock.transformer.json b/artifacts/src/contracts/ordinal-lock.transformer.json deleted file mode 100644 index 1a08d71..0000000 --- a/artifacts/src/contracts/ordinal-lock.transformer.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "success": true, - "errors": [], - "scryptfile": "src/contracts/ordinal-lock.scrypt", - "sourceMapFile": "src/contracts/ordinal-lock.scrypt.map", - "ctxMethods": [ - "purchase" - ] -} \ No newline at end of file diff --git a/dist/src/contracts/ordinal-lock.js b/dist/src/contracts/ordinal-lock.js deleted file mode 100644 index f1dc161..0000000 --- a/dist/src/contracts/ordinal-lock.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.OrdinalLock = void 0; -const scrypt_ts_1 = require("scrypt-ts"); -class OrdinalLock extends scrypt_ts_1.SmartContract { - constructor(seller, payOutput) { - super(...arguments); - this.seller = seller; - this.payOutput = payOutput; - } - purchase(selfOutput, trailingOutputs) { - (0, scrypt_ts_1.assert)((0, scrypt_ts_1.hash256)(selfOutput + this.payOutput + trailingOutputs) == this.ctx.hashOutputs); - } - cancel(sig, pubkey) { - (0, scrypt_ts_1.assert)(this.seller == (0, scrypt_ts_1.hash160)(pubkey), 'bad seller'); - (0, scrypt_ts_1.assert)(this.checkSig(sig, pubkey), 'signature check failed'); - } -} -__decorate([ - (0, scrypt_ts_1.prop)() -], OrdinalLock.prototype, "seller", void 0); -__decorate([ - (0, scrypt_ts_1.prop)() -], OrdinalLock.prototype, "payOutput", void 0); -__decorate([ - (0, scrypt_ts_1.method)(scrypt_ts_1.SigHash.ANYONECANPAY_ALL) -], OrdinalLock.prototype, "purchase", null); -__decorate([ - (0, scrypt_ts_1.method)() -], OrdinalLock.prototype, "cancel", null); -exports.OrdinalLock = OrdinalLock; -//# sourceMappingURL=ordinal-lock.js.map \ No newline at end of file diff --git a/dist/src/contracts/ordinal-lock.js.map b/dist/src/contracts/ordinal-lock.js.map deleted file mode 100644 index 07addf4..0000000 --- a/dist/src/contracts/ordinal-lock.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ordinal-lock.js","sourceRoot":"","sources":["../../../src/contracts/ordinal-lock.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yCAYkB;AAElB,MAAa,WAAY,SAAQ,yBAAa;IAO1C,YAAY,MAAkB,EAAE,SAAqB;QACjD,KAAK,CAAC,GAAG,SAAS,CAAC,CAAA;QAEnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAGM,QAAQ,CAAC,UAAsB,EAAE,eAA2B;QAC/D,IAAA,kBAAM,EAAC,IAAA,mBAAO,EAAC,UAAU,GAAG,IAAI,CAAC,SAAS,GAAG,eAAe,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;IAC1F,CAAC;IAGM,MAAM,CAAC,GAAQ,EAAE,MAAc;QAClC,IAAA,kBAAM,EAAC,IAAI,CAAC,MAAM,IAAI,IAAA,mBAAO,EAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAA;QACpD,IAAA,kBAAM,EAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,wBAAwB,CAAC,CAAA;IAChE,CAAC;CACJ;AAtBG;IADC,IAAA,gBAAI,GAAE;2CACW;AAGlB;IADC,IAAA,gBAAI,GAAE;8CACc;AAUrB;IADC,IAAA,kBAAM,EAAC,mBAAO,CAAC,gBAAgB,CAAC;2CAGhC;AAGD;IADC,IAAA,kBAAM,GAAE;yCAIR;AAvBL,kCAwBC"} \ No newline at end of file diff --git a/dist/tests/local/ordinal-lock.test.js b/dist/tests/local/ordinal-lock.test.js deleted file mode 100644 index bb3d33e..0000000 --- a/dist/tests/local/ordinal-lock.test.js +++ /dev/null @@ -1,80 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const chai_1 = require("chai"); -const scrypt_ts_1 = require("scrypt-ts"); -const ordinal_lock_1 = require("../../src/contracts/ordinal-lock"); -const txHelper_1 = require("./utils/txHelper"); -const chai_as_promised_1 = __importDefault(require("chai-as-promised")); -(0, chai_1.use)(chai_as_promised_1.default); -const [sellerPriv, sellerPub, sellerPKH, sellerAdd] = (0, txHelper_1.randomPrivateKey)(); -const [badPriv, badPub, badPKH, badAdd] = (0, txHelper_1.randomPrivateKey)(); -describe('Test SmartContract `OrdinalLock`', () => { - let instance; - const payOut = new scrypt_ts_1.bsv.Transaction.Output({ - script: scrypt_ts_1.bsv.Script.fromAddress(sellerAdd), - satoshis: 1000, - }) - .toBufferWriter() - .toBuffer(); - let deployTx; - before(async () => { - await ordinal_lock_1.OrdinalLock.compile(); - instance = new ordinal_lock_1.OrdinalLock((0, scrypt_ts_1.Ripemd160)(sellerPKH.toString('hex')), payOut.toString('hex')); - // instance.bindTxBuilder('purchase', OrdinalLock.purchaseTxBuilder) - await instance.connect((0, txHelper_1.getDummySigner)([sellerPriv])); - deployTx = await instance.deploy(1); - console.log('OrdinalLock contract deployed: ', deployTx.id); - }); - it('should pass the cancel method unit test successfully.', async () => { - const { tx: callTx, atInputIndex } = await instance.methods.cancel((sigResps) => (0, scrypt_ts_1.findSig)(sigResps, sellerPub), (0, scrypt_ts_1.PubKey)(sellerPub.toString()), { - pubKeyOrAddrToSign: [sellerPub], - }); - const result = callTx.verifyScript(atInputIndex); - (0, chai_1.expect)(result.success, result.error).to.eq(true); - }); - it('should fail the cancel method unit test with bad seller.', async () => { - (0, chai_1.expect)(instance.methods.cancel((sigResps) => (0, scrypt_ts_1.findSig)(sigResps, sellerPub), (0, scrypt_ts_1.PubKey)(badPub.toString()), { - pubKeyOrAddrToSign: [sellerPub], - })).to.be.rejectedWith('bad seller'); - }); - it('should fail the cancel method unit test with signature check failed.', async () => { - (0, chai_1.expect)(instance.methods.cancel((sigResps) => (0, scrypt_ts_1.findSig)(sigResps, badPub), (0, scrypt_ts_1.PubKey)(sellerPub.toString()), { - pubKeyOrAddrToSign: [badPub], - })).to.be.rejectedWith('signature check failed'); - }); - it('should pass the purchase method unit test successfully.', async () => { - const tx = new scrypt_ts_1.bsv.Transaction() - .addOutput(new scrypt_ts_1.bsv.Transaction.Output({ - script: new scrypt_ts_1.bsv.Script(sellerAdd), - satoshis: instance.balance, - })) - // // build payment output - .addOutput(scrypt_ts_1.bsv.Transaction.Output.fromBufferReader(new scrypt_ts_1.bsv.encoding.BufferReader(Buffer.from(instance.payOutput, 'hex')))) - // // add contract input - .from({ - txId: deployTx.id, - outputIndex: 0, - script: deployTx.outputs[0].script.toString(), - satoshis: deployTx.outputs[0].satoshis, - }); - // const asm = `${tx.outputs[0].toBufferWriter().toBuffer().toString('hex')} OP_0 ${tx.getPreimage(0, 0xc1, false)} OP_0` - // const preimage = tx.pre - const script = scrypt_ts_1.bsv.Script.fromBuffer(Buffer.alloc(0)) - .add(tx.outputs[0].toBufferWriter().toBuffer()) - .add(scrypt_ts_1.bsv.Opcode.OP_0) - .add(scrypt_ts_1.bsv.Transaction.Sighash.sighashPreimage(tx, 0xc1, 0, deployTx.outputs[0].script, new scrypt_ts_1.bsv.crypto.BN(deployTx.outputs[0].satoshis), 0x40)) - .add(scrypt_ts_1.bsv.Opcode.OP_0); - tx.inputs[0].setScript(script); - // console.log('Tx: ', JSON.stringify(tx)) - const result = tx.verifyScript(0); - (0, chai_1.expect)(result.success, result.error).to.eq(true); - }); - it('should fail the purchase method unit test bad payOut.', async () => { - const badScript = scrypt_ts_1.bsv.Script.fromAddress(badAdd).toHex(); - (0, chai_1.expect)(instance.methods.purchase(badScript, {})).to.be.rejectedWith('bad self output'); - }); -}); -//# sourceMappingURL=ordinal-lock.test.js.map \ No newline at end of file diff --git a/dist/tests/local/ordinal-lock.test.js.map b/dist/tests/local/ordinal-lock.test.js.map deleted file mode 100644 index 3753e87..0000000 --- a/dist/tests/local/ordinal-lock.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ordinal-lock.test.js","sourceRoot":"","sources":["../../../tests/local/ordinal-lock.test.ts"],"names":[],"mappings":"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"} \ No newline at end of file diff --git a/dist/tests/local/utils/txHelper.js b/dist/tests/local/utils/txHelper.js deleted file mode 100644 index 5616e2e..0000000 --- a/dist/tests/local/utils/txHelper.js +++ /dev/null @@ -1,37 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.randomPrivateKey = exports.getDummyUTXO = exports.getDummySigner = exports.dummyUTXO = exports.inputIndex = exports.inputSatoshis = void 0; -const crypto_1 = require("crypto"); -const scrypt_ts_1 = require("scrypt-ts"); -const privateKey_1 = require("../../utils/privateKey"); -exports.inputSatoshis = 10000; -exports.inputIndex = 0; -exports.dummyUTXO = { - txId: (0, crypto_1.randomBytes)(32).toString('hex'), - outputIndex: 0, - script: '', - satoshis: exports.inputSatoshis, -}; -function getDummySigner(privateKey) { - if (global.dummySigner === undefined) { - global.dummySigner = new scrypt_ts_1.TestWallet(privateKey_1.myPrivateKey, new scrypt_ts_1.DummyProvider()); - } - if (privateKey !== undefined) { - global.dummySigner.addPrivateKey(privateKey); - } - return global.dummySigner; -} -exports.getDummySigner = getDummySigner; -function getDummyUTXO(satoshis = exports.inputSatoshis) { - return Object.assign({}, exports.dummyUTXO, { satoshis }); -} -exports.getDummyUTXO = getDummyUTXO; -function randomPrivateKey() { - const privateKey = scrypt_ts_1.bsv.PrivateKey.fromRandom('testnet'); - const publicKey = scrypt_ts_1.bsv.PublicKey.fromPrivateKey(privateKey); - const publicKeyHash = scrypt_ts_1.bsv.crypto.Hash.sha256ripemd160(publicKey.toBuffer()); - const address = publicKey.toAddress(); - return [privateKey, publicKey, publicKeyHash, address]; -} -exports.randomPrivateKey = randomPrivateKey; -//# sourceMappingURL=txHelper.js.map \ No newline at end of file diff --git a/dist/tests/local/utils/txHelper.js.map b/dist/tests/local/utils/txHelper.js.map deleted file mode 100644 index 8411dff..0000000 --- a/dist/tests/local/utils/txHelper.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"txHelper.js","sourceRoot":"","sources":["../../../../tests/local/utils/txHelper.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AACpC,yCAAgE;AAChE,uDAAqD;AAExC,QAAA,aAAa,GAAG,KAAK,CAAA;AAErB,QAAA,UAAU,GAAG,CAAC,CAAA;AAEd,QAAA,SAAS,GAAG;IACrB,IAAI,EAAE,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;IACrC,WAAW,EAAE,CAAC;IACd,MAAM,EAAE,EAAE;IACV,QAAQ,EAAE,qBAAa;CAC1B,CAAA;AAED,SAAgB,cAAc,CAC1B,UAA8C;IAE9C,IAAI,MAAM,CAAC,WAAW,KAAK,SAAS,EAAE;QAClC,MAAM,CAAC,WAAW,GAAG,IAAI,sBAAU,CAAC,yBAAY,EAAE,IAAI,yBAAa,EAAE,CAAC,CAAA;KACzE;IACD,IAAI,UAAU,KAAK,SAAS,EAAE;QAC1B,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;KAC/C;IACD,OAAO,MAAM,CAAC,WAAW,CAAA;AAC7B,CAAC;AAVD,wCAUC;AAED,SAAgB,YAAY,CAAC,WAAmB,qBAAa;IACzD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,iBAAS,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;AACrD,CAAC;AAFD,oCAEC;AAED,SAAgB,gBAAgB;IAC5B,MAAM,UAAU,GAAG,eAAG,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IACvD,MAAM,SAAS,GAAG,eAAG,CAAC,SAAS,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;IAC1D,MAAM,aAAa,GAAG,eAAG,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC3E,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,EAAE,CAAA;IACrC,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,CAAU,CAAA;AACnE,CAAC;AAND,4CAMC"} \ No newline at end of file diff --git a/dist/tests/testnet/ordinal-lock.js b/dist/tests/testnet/ordinal-lock.js deleted file mode 100644 index b633ae7..0000000 --- a/dist/tests/testnet/ordinal-lock.js +++ /dev/null @@ -1,44 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const ordinal_lock_1 = require("../../src/contracts/ordinal-lock"); -const txHelper_1 = require("./utils/txHelper"); -const scrypt_ts_1 = require("scrypt-ts"); -const privateKey_1 = require("../utils/privateKey"); -const payScript = scrypt_ts_1.bsv.Script.fromAddress(privateKey_1.myAddress); -// const paySats = 1000n -const payOut = new scrypt_ts_1.bsv.Transaction.Output({ - script: payScript, - satoshis: 1000, -}) - .toBufferWriter() - .toBuffer(); -async function main() { - await ordinal_lock_1.OrdinalLock.compile(); - let instance = new ordinal_lock_1.OrdinalLock((0, scrypt_ts_1.Ripemd160)(privateKey_1.myPublicKeyHash.toString('hex')), payOut.toString('hex')); - await instance.connect((0, txHelper_1.getDefaultSigner)(privateKey_1.myPrivateKey)); - // instance.bindTxBuilder('purchase', OrdinalLock.purchaseTxBuilder) - // contract deployment - let deployTx = await instance.deploy(1); - console.log('OrdinalLock contract deployed: ', deployTx.id); - // contract call - const { tx: cancelTx } = await instance.methods.cancel((sigResps) => (0, scrypt_ts_1.findSig)(sigResps, privateKey_1.myPublicKey), (0, scrypt_ts_1.PubKey)(privateKey_1.myPublicKey.toString()), { - pubKeyOrAddrToSign: [privateKey_1.myPublicKey], - }); - console.log('OrdinalLock contract `cancel` called: ', cancelTx.id); - instance = new ordinal_lock_1.OrdinalLock((0, scrypt_ts_1.Ripemd160)(privateKey_1.myPublicKeyHash.toString('hex')), payOut.toString('hex')); - await instance.connect((0, txHelper_1.getDefaultSigner)(privateKey_1.myPrivateKey)); - // instance.bindTxBuilder('purchase', OrdinalLock.purchaseTxBuilder) - // contract deployment - deployTx = await instance.deploy(1); - console.log('OrdinalLock contract deployed: ', deployTx.id); - const { tx: purchaseTx } = await instance.methods.purchase(payScript, { - changeAddress: privateKey_1.myAddress, - }); - console.log('OrdinalLock contract `purchase` called: ', purchaseTx.id); -} -describe('Test SmartContract `OrdinalLock` on testnet', () => { - it('should succeed', async () => { - await main(); - }); -}); -//# sourceMappingURL=ordinal-lock.js.map \ No newline at end of file diff --git a/dist/tests/testnet/ordinal-lock.js.map b/dist/tests/testnet/ordinal-lock.js.map deleted file mode 100644 index af91464..0000000 --- a/dist/tests/testnet/ordinal-lock.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ordinal-lock.js","sourceRoot":"","sources":["../../../tests/testnet/ordinal-lock.ts"],"names":[],"mappings":";;AAAA,mEAA8D;AAC9D,+CAAmD;AACnD,yCAA8E;AAC9E,oDAK4B;AAE5B,MAAM,SAAS,GAAG,eAAG,CAAC,MAAM,CAAC,WAAW,CAAC,sBAAS,CAAC,CAAA;AACnD,wBAAwB;AACxB,MAAM,MAAM,GAAG,IAAI,eAAG,CAAC,WAAW,CAAC,MAAM,CAAC;IACtC,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,IAAI;CACjB,CAAC;KACG,cAAc,EAAE;KAChB,QAAQ,EAAE,CAAA;AAEf,KAAK,UAAU,IAAI;IACf,MAAM,0BAAW,CAAC,OAAO,EAAE,CAAA;IAC3B,IAAI,QAAQ,GAAG,IAAI,0BAAW,CAC1B,IAAA,qBAAS,EAAC,4BAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAC1C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzB,CAAA;IACD,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAA,2BAAgB,EAAC,yBAAY,CAAC,CAAC,CAAA;IAEtD,oEAAoE;IAEpE,sBAAsB;IACtB,IAAI,QAAQ,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACvC,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAA;IAE3D,gBAAgB;IAChB,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,MAAM,CAClD,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,mBAAO,EAAC,QAAQ,EAAE,wBAAW,CAAC,EAC5C,IAAA,kBAAM,EAAC,wBAAW,CAAC,QAAQ,EAAE,CAAC,EAC9B;QACI,kBAAkB,EAAE,CAAC,wBAAW,CAAC;KACF,CACtC,CAAA;IACD,OAAO,CAAC,GAAG,CAAC,wCAAwC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAA;IAElE,QAAQ,GAAG,IAAI,0BAAW,CACtB,IAAA,qBAAS,EAAC,4BAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAC1C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzB,CAAA;IACD,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAA,2BAAgB,EAAC,yBAAY,CAAC,CAAC,CAAA;IACtD,oEAAoE;IAEpE,sBAAsB;IACtB,QAAQ,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACnC,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAA;IAE3D,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE;QAClE,aAAa,EAAE,sBAAS;KACO,CAAC,CAAA;IAEpC,OAAO,CAAC,GAAG,CAAC,0CAA0C,EAAE,UAAU,CAAC,EAAE,CAAC,CAAA;AAC1E,CAAC;AAED,QAAQ,CAAC,6CAA6C,EAAE,GAAG,EAAE;IACzD,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;QAC5B,MAAM,IAAI,EAAE,CAAA;IAChB,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/tests/testnet/utils/txHelper.js b/dist/tests/testnet/utils/txHelper.js deleted file mode 100644 index 6702e32..0000000 --- a/dist/tests/testnet/utils/txHelper.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getDefaultSigner = exports.randomPrivateKey = exports.sleep = exports.inputSatoshis = void 0; -const privateKey_1 = require("../../utils/privateKey"); -const scrypt_ts_1 = require("scrypt-ts"); -exports.inputSatoshis = 10000; -const sleep = async (seconds) => { - return new Promise((resolve) => { - setTimeout(() => { - resolve({}); - }, seconds * 1000); - }); -}; -exports.sleep = sleep; -function randomPrivateKey() { - const privateKey = scrypt_ts_1.bsv.PrivateKey.fromRandom('testnet'); - const publicKey = scrypt_ts_1.bsv.PublicKey.fromPrivateKey(privateKey); - const publicKeyHash = scrypt_ts_1.bsv.crypto.Hash.sha256ripemd160(publicKey.toBuffer()); - const address = publicKey.toAddress(); - return [privateKey, publicKey, publicKeyHash, address]; -} -exports.randomPrivateKey = randomPrivateKey; -function getDefaultSigner(privateKey) { - if (global.testnetSigner === undefined) { - global.testnetSigner = new scrypt_ts_1.TestWallet(privateKey_1.myPrivateKey, new scrypt_ts_1.DefaultProvider()); - } - if (privateKey !== undefined) { - global.testnetSigner.addPrivateKey(privateKey); - } - return global.testnetSigner; -} -exports.getDefaultSigner = getDefaultSigner; -//# sourceMappingURL=txHelper.js.map \ No newline at end of file diff --git a/dist/tests/testnet/utils/txHelper.js.map b/dist/tests/testnet/utils/txHelper.js.map deleted file mode 100644 index 026a545..0000000 --- a/dist/tests/testnet/utils/txHelper.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"txHelper.js","sourceRoot":"","sources":["../../../../tests/testnet/utils/txHelper.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AACrD,yCAA4D;AAE/C,QAAA,aAAa,GAAG,KAAK,CAAA;AAE3B,MAAM,KAAK,GAAG,KAAK,EAAE,OAAe,EAAE,EAAE;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,UAAU,CAAC,GAAG,EAAE;YACZ,OAAO,CAAC,EAAE,CAAC,CAAA;QACf,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AANY,QAAA,KAAK,SAMjB;AAED,SAAgB,gBAAgB;IAC5B,MAAM,UAAU,GAAG,eAAG,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IACvD,MAAM,SAAS,GAAG,eAAG,CAAC,SAAS,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;IAC1D,MAAM,aAAa,GAAG,eAAG,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC3E,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,EAAE,CAAA;IACrC,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,CAAU,CAAA;AACnE,CAAC;AAND,4CAMC;AAED,SAAgB,gBAAgB,CAC5B,UAA8C;IAE9C,IAAI,MAAM,CAAC,aAAa,KAAK,SAAS,EAAE;QACpC,MAAM,CAAC,aAAa,GAAG,IAAI,sBAAU,CACjC,yBAAY,EACZ,IAAI,2BAAe,EAAE,CACxB,CAAA;KACJ;IACD,IAAI,UAAU,KAAK,SAAS,EAAE;QAC1B,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;KACjD;IACD,OAAO,MAAM,CAAC,aAAa,CAAA;AAC/B,CAAC;AAbD,4CAaC"} \ No newline at end of file diff --git a/dist/tests/utils/privateKey.js b/dist/tests/utils/privateKey.js deleted file mode 100644 index f53ec41..0000000 --- a/dist/tests/utils/privateKey.js +++ /dev/null @@ -1,59 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.myAddress = exports.myPublicKeyHash = exports.myPublicKey = exports.myPrivateKey = exports.showAddr = exports.genPrivKey = void 0; -const scrypt_ts_1 = require("scrypt-ts"); -const dotenv = __importStar(require("dotenv")); -const fs = __importStar(require("fs")); -const dotenvConfigPath = '.env'; -dotenv.config({ path: dotenvConfigPath }); -// fill in private key on testnet in WIF here -let privKey = process.env.PRIVATE_KEY; -if (!privKey) { - genPrivKey(); -} -else { - showAddr(scrypt_ts_1.bsv.PrivateKey.fromWIF(privKey)); -} -function genPrivKey() { - const newPrivKey = scrypt_ts_1.bsv.PrivateKey.fromRandom('testnet'); - console.log(`Missing private key, generating a new one ... -Private key generated: '${newPrivKey.toWIF()}' -You can fund its address '${newPrivKey.toAddress()}' from the sCrypt faucet https://scrypt.io/faucet`); - // auto generate .env file with new generated key - fs.writeFileSync(dotenvConfigPath, `PRIVATE_KEY="${newPrivKey}"`); - privKey = newPrivKey.toWIF(); -} -exports.genPrivKey = genPrivKey; -function showAddr(privKey) { - console.log(`Private key already present ... -You can fund its address '${privKey.toAddress()}' from the sCrypt faucet https://scrypt.io/faucet`); -} -exports.showAddr = showAddr; -exports.myPrivateKey = scrypt_ts_1.bsv.PrivateKey.fromWIF(privKey); -exports.myPublicKey = scrypt_ts_1.bsv.PublicKey.fromPrivateKey(exports.myPrivateKey); -exports.myPublicKeyHash = scrypt_ts_1.bsv.crypto.Hash.sha256ripemd160(exports.myPublicKey.toBuffer()); -exports.myAddress = exports.myPublicKey.toAddress(); -//# sourceMappingURL=privateKey.js.map \ No newline at end of file diff --git a/dist/tests/utils/privateKey.js.map b/dist/tests/utils/privateKey.js.map deleted file mode 100644 index 4fbd284..0000000 --- a/dist/tests/utils/privateKey.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"privateKey.js","sourceRoot":"","sources":["../../../tests/utils/privateKey.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA+B;AAC/B,+CAAgC;AAChC,uCAAwB;AAExB,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAC/B,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAA;AAEzC,6CAA6C;AAC7C,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;AACrC,IAAI,CAAC,OAAO,EAAE;IACV,UAAU,EAAE,CAAA;CACf;KAAM;IACH,QAAQ,CAAC,eAAG,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;CAC5C;AAED,SAAgB,UAAU;IACtB,MAAM,UAAU,GAAG,eAAG,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IACvD,OAAO,CAAC,GAAG,CAAC;0BACU,UAAU,CAAC,KAAK,EAAE;4BAChB,UAAU,CAAC,SAAS,EAAE,mDAAmD,CAAC,CAAA;IAClG,iDAAiD;IACjD,EAAE,CAAC,aAAa,CAAC,gBAAgB,EAAE,gBAAgB,UAAU,GAAG,CAAC,CAAA;IACjE,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,CAAA;AAChC,CAAC;AARD,gCAQC;AAED,SAAgB,QAAQ,CAAC,OAAuB;IAC5C,OAAO,CAAC,GAAG,CAAC;4BACY,OAAO,CAAC,SAAS,EAAE,mDAAmD,CAAC,CAAA;AACnG,CAAC;AAHD,4BAGC;AAEY,QAAA,YAAY,GAAG,eAAG,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAC9C,QAAA,WAAW,GAAG,eAAG,CAAC,SAAS,CAAC,cAAc,CAAC,oBAAY,CAAC,CAAA;AACxD,QAAA,eAAe,GAAG,eAAG,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAC1D,mBAAW,CAAC,QAAQ,EAAE,CACzB,CAAA;AACY,QAAA,SAAS,GAAG,mBAAW,CAAC,SAAS,EAAE,CAAA"} \ No newline at end of file diff --git a/package.json b/package.json index 821190a..c576dd6 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "dependencies": { "dotenv": "^16.0.3", - "scrypt-ts": "beta" + "scrypt-ts": "=0.2.1-beta.2" }, "devDependencies": { "@types/chai": "^4.3.4", diff --git a/src/contracts/ordinal-lock.ts b/src/contracts/ordinal-lock.ts index 010f23a..986c66b 100644 --- a/src/contracts/ordinal-lock.ts +++ b/src/contracts/ordinal-lock.ts @@ -10,6 +10,9 @@ import { SmartContract, Sig, SigHash, + MethodCallOptions, + ContractTransaction, + bsv, } from 'scrypt-ts' export class OrdinalLock extends SmartContract { @@ -39,4 +42,49 @@ export class OrdinalLock extends SmartContract { assert(this.seller == hash160(pubkey), 'bad seller') assert(this.checkSig(sig, pubkey), 'signature check failed') } + + static purchaseTxBuilder( + current: OrdinalLock, + options: MethodCallOptions, + selfOutput: ByteString, + trailingOutputs: ByteString + ): Promise { + const unsignedTx: bsv.Transaction = new bsv.Transaction() + // build next instance output + .addOutput( + bsv.Transaction.Output.fromBufferReader( + new bsv.encoding.BufferReader( + Buffer.from(selfOutput, 'hex') + ) + ) + ) + // build payment output + .addOutput( + bsv.Transaction.Output.fromBufferReader( + new bsv.encoding.BufferReader( + Buffer.from(current.payOutput, 'hex') + ) + ) + ) + .addOutput( + bsv.Transaction.Output.fromBufferReader( + new bsv.encoding.BufferReader( + Buffer.from(trailingOutputs, 'hex') + ) + ) + ) + // add contract input + .addInput(current.buildContractInput()) + + if (options.changeAddress) { + // build change output + unsignedTx.change(options.changeAddress) + } + + return Promise.resolve({ + tx: unsignedTx, + atInputIndex: 0, + nexts: [], + }) + } } diff --git a/tests/local/ordinal-lock.test.ts b/tests/local/ordinal-lock.test.ts index b17b0b8..6e21109 100644 --- a/tests/local/ordinal-lock.test.ts +++ b/tests/local/ordinal-lock.test.ts @@ -1,12 +1,14 @@ import { expect, use } from 'chai' import { bsv, + buildOpreturnScript, findSig, MethodCallOptions, PubKey, Ripemd160, SigHash, SmartContract, + toHex, TransactionResponse, } from 'scrypt-ts' import { OrdinalLock } from '../../src/contracts/ordinal-lock' @@ -35,7 +37,7 @@ describe('Test SmartContract `OrdinalLock`', () => { payOut.toString('hex') ) - // instance.bindTxBuilder('purchase', OrdinalLock.purchaseTxBuilder) + instance.bindTxBuilder('purchase', OrdinalLock.purchaseTxBuilder) await instance.connect(getDummySigner([sellerPriv])) deployTx = await instance.deploy(1) @@ -79,49 +81,34 @@ describe('Test SmartContract `OrdinalLock`', () => { }) it('should pass the purchase method unit test successfully.', async () => { - const tx = new bsv.Transaction() - .addOutput( - new bsv.Transaction.Output({ - script: new bsv.Script(sellerAdd), - satoshis: instance.balance, - }) - ) - // // build payment output - .addOutput( - bsv.Transaction.Output.fromBufferReader( - new bsv.encoding.BufferReader( - Buffer.from(instance.payOutput, 'hex') - ) - ) - ) - // // add contract input - .from({ - txId: deployTx.id, - outputIndex: 0, - script: deployTx.outputs[0].script.toString(), - satoshis: deployTx.outputs[0].satoshis, + const selfOutput = toHex( + new bsv.Transaction.Output({ + script: new bsv.Script(sellerAdd), + satoshis: instance.balance, }) + .toBufferWriter() + .toBuffer() + ) - // const asm = `${tx.outputs[0].toBufferWriter().toBuffer().toString('hex')} OP_0 ${tx.getPreimage(0, 0xc1, false)} OP_0` - // const preimage = tx.pre - const script = bsv.Script.fromBuffer(Buffer.alloc(0)) - .add(tx.outputs[0].toBufferWriter().toBuffer()) - .add(bsv.Opcode.OP_0) - .add( - bsv.Transaction.Sighash.sighashPreimage( - tx, - 0xc1, - 0, - deployTx.outputs[0].script, - new bsv.crypto.BN(deployTx.outputs[0].satoshis), - 0x40 - ) - ) - .add(bsv.Opcode.OP_0) - tx.inputs[0].setScript(script) + const trailingOutputs = toHex( + new bsv.Transaction.Output({ + script: buildOpreturnScript('00'), + satoshis: instance.balance, + }) + .toBufferWriter() + .toBuffer() + ) - // console.log('Tx: ', JSON.stringify(tx)) - const result = tx.verifyScript(0) + const { tx: callTx, atInputIndex } = await instance.methods.purchase( + selfOutput, + trailingOutputs, + { + pubKeyOrAddrToSign: [sellerPub], + partiallySigned: true, + autoPayFee: false, + } as MethodCallOptions + ) + const result = callTx.verifyScript(atInputIndex) expect(result.success, result.error).to.eq(true) }) diff --git a/tests/testnet/ordinal-lock.ts b/tests/testnet/ordinal-lock.ts index 5b24ec9..e581960 100644 --- a/tests/testnet/ordinal-lock.ts +++ b/tests/testnet/ordinal-lock.ts @@ -1,6 +1,16 @@ import { OrdinalLock } from '../../src/contracts/ordinal-lock' -import { getDefaultSigner } from './utils/txHelper' -import { bsv, Ripemd160, findSig, MethodCallOptions, PubKey } from 'scrypt-ts' +import { getDefaultSigner, randomPrivateKey } from './utils/txHelper' +import { + bsv, + Ripemd160, + findSig, + MethodCallOptions, + PubKey, + buildOpreturnScript, + toHex, + DefaultProvider, + TestWallet, +} from 'scrypt-ts' import { myPrivateKey, myPublicKey, @@ -25,8 +35,6 @@ async function main() { ) await instance.connect(getDefaultSigner(myPrivateKey)) - // instance.bindTxBuilder('purchase', OrdinalLock.purchaseTxBuilder) - // contract deployment let deployTx = await instance.deploy(1) console.log('OrdinalLock contract deployed: ', deployTx.id) @@ -46,17 +54,78 @@ async function main() { payOut.toString('hex') ) await instance.connect(getDefaultSigner(myPrivateKey)) - // instance.bindTxBuilder('purchase', OrdinalLock.purchaseTxBuilder) + instance.bindTxBuilder('purchase', OrdinalLock.purchaseTxBuilder) // contract deployment deployTx = await instance.deploy(1) console.log('OrdinalLock contract deployed: ', deployTx.id) - const { tx: purchaseTx } = await instance.methods.purchase(payScript, { - changeAddress: myAddress, - } as MethodCallOptions) + const selfOutput = toHex( + new bsv.Transaction.Output({ + script: new bsv.Script(myAddress), + satoshis: instance.balance, + }) + .toBufferWriter() + .toBuffer() + ) + + const trailingOutputs = toHex( + new bsv.Transaction.Output({ + script: buildOpreturnScript('00'), + satoshis: instance.balance, + }) + .toBufferWriter() + .toBuffer() + ) + + const { tx: callTx, atInputIndex } = await instance.methods.purchase( + selfOutput, + trailingOutputs, + { + pubKeyOrAddrToSign: [myPublicKey], + partiallySigned: true, + autoPayFee: false, + } as MethodCallOptions + ) + const result = callTx.verifyScript(atInputIndex) + + console.log('OrdinalLock contract `purchase` verify: ', result) + + const needSatoshiAsFee = + callTx.outputAmount + callTx.getEstimateFee() + callTx.inputAmount + + console.log('needSatoshiAsFee', needSatoshiAsFee) + + // now you have a partially Signed tx, send this tx to user , then user add a input, and sign it + + const userPrivateKey = bsv.PrivateKey.fromWIF( + 'cS98v9dfvPsLUcpriCpiRw3tZ65sp77XjDr5ZJtnXUvQKHQiqtQL' + ) + + const userSigner = new TestWallet( + userPrivateKey, + new DefaultProvider({ + network: bsv.Networks.testnet, + }) + ) + + const utxos = await userSigner.listUnspent(userPrivateKey.toAddress(), { + minSatoshis: needSatoshiAsFee, + }) + + // add p2pkh input to pay fee + callTx.from(utxos) + + console.log('utxos', utxos) + + // only sign p2pkh input + await userSigner.signTransaction(callTx) + + console.log('check fee', callTx.getFee(), callTx.getEstimateFee()) + + await userSigner.provider.sendTransaction(callTx) - console.log('OrdinalLock contract `purchase` called: ', purchaseTx.id) + console.log('OrdinalLock contract `purchase` called: ', callTx.id) } describe('Test SmartContract `OrdinalLock` on testnet', () => { diff --git a/tests/testnet/utils/txHelper.ts b/tests/testnet/utils/txHelper.ts index 9ced911..c70e2cf 100644 --- a/tests/testnet/utils/txHelper.ts +++ b/tests/testnet/utils/txHelper.ts @@ -25,7 +25,9 @@ export function getDefaultSigner( if (global.testnetSigner === undefined) { global.testnetSigner = new TestWallet( myPrivateKey, - new DefaultProvider() + new DefaultProvider({ + network: bsv.Networks.testnet, + }) ) } if (privateKey !== undefined) {