From d8993655ca9b0074d6d22c1680fcd01b23a62054 Mon Sep 17 00:00:00 2001 From: Rosco Kalis Date: Tue, 3 Dec 2024 14:13:35 +0100 Subject: [PATCH] Bump version to 0.10.4 --- examples/bug.cash | 49 ++++++++++++++++++++++++++ examples/package.json | 6 ++-- examples/testing-suite/package.json | 6 ++-- packages/cashc/package.json | 4 +-- packages/cashc/src/index.ts | 2 +- packages/cashscript/package.json | 4 +-- packages/utils/package.json | 2 +- website/docs/releases/release-notes.md | 5 +++ 8 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 examples/bug.cash diff --git a/examples/bug.cash b/examples/bug.cash new file mode 100644 index 00000000..3d5958e4 --- /dev/null +++ b/examples/bug.cash @@ -0,0 +1,49 @@ +pragma cashscript ^0.10.0; + +contract PriceContract( + bytes tokenIdOracleContract + ) { + // function updatePrice + // Trigger oracle sequence update to avoid letting borrowers spawn coins using old price data + // + // Inputs: 00-pricecontract, 01-oraclecontract, ?02-feeBCH + // Outputs: 00-pricecontract, ?01-changeBCH + + function updatePrice() { + require(this.activeInputIndex == 0, "Parity contract must always be at input index 0"); + + require(tx.outputs[0].lockingBytecode == tx.inputs[0].lockingBytecode, "Recreate contract at output0 - invalid lockingBytecode"); + require(tx.outputs[0].tokenCategory == tx.inputs[0].tokenCategory, "Recreate contract at output0 - invalid tokenCategory"); + require(tx.outputs[0].value == 1000, "Recreate contract at output0 - needs to hold exactly 1000 sats"); + require(tx.outputs[0].tokenAmount == tx.inputs[0].tokenAmount, "Invalid tokenAmount, needs to maintain atleast current tokenAmount"); + + bytes contractSeq = tx.inputs[0].nftCommitment.split(1)[1].split(6)[0]; + + require(tokenIdOracleContract == tx.inputs[1].tokenCategory); + + // Parse oracle data (Oracle price is denominated in USD cents/BCH) + bytes oracleSeqBytes = tx.inputs[1].nftCommitment.split(6)[0]; + int oracleSeq = int(oracleSeqBytes); + + // Verify oracle sequence + require(oracleSeq > int(contractSeq), "Invalid oracle sequence, should be more recent than current contract sequence"); + + require(tx.outputs[0].nftCommitment == 0x00 + tx.inputs[1].nftCommitment, "Invalid nftCommitment, commitment should be the oracle sequence"); + } + + // function sharePrice + // Provides latest oracle price to various other contracts + // + // Inputs: 00-parity, ... + // Outputs: 00-parity, ... + + function sharePrice() { + require(tx.outputs[this.activeInputIndex].lockingBytecode == tx.inputs[this.activeInputIndex].lockingBytecode, "Recreate contract at output0 - invalid lockingBytecode"); + require(tx.outputs[this.activeInputIndex].tokenCategory == tx.inputs[this.activeInputIndex].tokenCategory, "Recreate contract at output0 - invalid tokenCategory"); + require(tx.outputs[this.activeInputIndex].value == 1000, "Recreate contract at output0 - needs to hold exactly 1000 sats"); + // Allow giving the contract more tokens + require(tx.outputs[this.activeInputIndex].tokenAmount >= tx.inputs[this.activeInputIndex].tokenAmount, "Invalid tokenAmount, needs to maintain atleast current tokenAmount"); + // keep same contract state + require(tx.outputs[this.activeInputIndex].nftCommitment == tx.inputs[this.activeInputIndex].nftCommitment, "Invalid nftCommitment, commitment should be replicated"); + } +} diff --git a/examples/package.json b/examples/package.json index e33fd1fb..914e476c 100644 --- a/examples/package.json +++ b/examples/package.json @@ -1,7 +1,7 @@ { "name": "cashscript-examples", "private": true, - "version": "0.10.3", + "version": "0.10.4", "description": "Usage examples of the CashScript SDK", "main": "p2pkh.js", "type": "module", @@ -13,8 +13,8 @@ "dependencies": { "@bitauth/libauth": "^3.0.0", "@types/node": "^12.7.8", - "cashc": "^0.10.3", - "cashscript": "^0.10.3", + "cashc": "^0.10.4", + "cashscript": "^0.10.4", "eslint": "^8.56.0", "typescript": "^4.9.5" } diff --git a/examples/testing-suite/package.json b/examples/testing-suite/package.json index 332a4b61..662204a4 100644 --- a/examples/testing-suite/package.json +++ b/examples/testing-suite/package.json @@ -1,6 +1,6 @@ { "name": "testing-suite", - "version": "0.10.3", + "version": "0.10.4", "description": "Example project to develop and test CashScript contracts", "main": "index.js", "type": "module", @@ -25,8 +25,8 @@ "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest" }, "dependencies": { - "cashc": "^0.10.3", - "cashscript": "^0.10.3", + "cashc": "^0.10.4", + "cashscript": "^0.10.4", "url-join": "^5.0.0" }, "devDependencies": { diff --git a/packages/cashc/package.json b/packages/cashc/package.json index 48e8a368..117c8829 100644 --- a/packages/cashc/package.json +++ b/packages/cashc/package.json @@ -1,6 +1,6 @@ { "name": "cashc", - "version": "0.10.3", + "version": "0.10.4", "description": "Compile Bitcoin Cash contracts to Bitcoin Cash Script or artifacts", "keywords": [ "bitcoin", @@ -50,7 +50,7 @@ }, "dependencies": { "@bitauth/libauth": "^3.0.0", - "@cashscript/utils": "^0.10.3", + "@cashscript/utils": "^0.10.4", "antlr4": "^4.13.1-patch-1", "commander": "^7.1.0", "semver": "^7.5.4" diff --git a/packages/cashc/src/index.ts b/packages/cashc/src/index.ts index 2539208b..afb70ba0 100644 --- a/packages/cashc/src/index.ts +++ b/packages/cashc/src/index.ts @@ -2,4 +2,4 @@ export * from './Errors.js'; export * as utils from '@cashscript/utils'; export { compileFile, compileString } from './compiler.js'; -export const version = '0.10.3'; +export const version = '0.10.4'; diff --git a/packages/cashscript/package.json b/packages/cashscript/package.json index 70d760c0..58eecbe7 100644 --- a/packages/cashscript/package.json +++ b/packages/cashscript/package.json @@ -1,6 +1,6 @@ { "name": "cashscript", - "version": "0.10.3", + "version": "0.10.4", "description": "Easily write and interact with Bitcoin Cash contracts", "keywords": [ "bitcoin cash", @@ -44,7 +44,7 @@ }, "dependencies": { "@bitauth/libauth": "^3.0.0", - "@cashscript/utils": "^0.10.3", + "@cashscript/utils": "^0.10.4", "@mr-zwets/bchn-api-wrapper": "^1.0.1", "delay": "^5.0.0", "electrum-cash": "^2.0.10", diff --git a/packages/utils/package.json b/packages/utils/package.json index 3aadd077..81a90662 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@cashscript/utils", - "version": "0.10.3", + "version": "0.10.4", "description": "CashScript utilities and types", "keywords": [ "bitcoin cash", diff --git a/website/docs/releases/release-notes.md b/website/docs/releases/release-notes.md index 5a9fb560..40760e93 100644 --- a/website/docs/releases/release-notes.md +++ b/website/docs/releases/release-notes.md @@ -2,6 +2,11 @@ title: Release Notes --- +## v0.10.4 + +#### cashc compiler +- :bug: Fix bug in new `--format ts` option. + ## v0.10.3 #### cashc compiler