Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
907eed5
Checkpoint after merge into upstream
mainnet-pat Nov 22, 2023
0de45e8
Stash
mainnet-pat Nov 22, 2023
41eeb46
Console logs ready
mainnet-pat Nov 23, 2023
c39c736
Add failure message to require statements
mainnet-pat Nov 23, 2023
d58d85f
Support require messages in libauth debug evaluation
mainnet-pat Nov 23, 2023
bb919ea
Transform most tests to be compatible with MockNetworkProvider
mainnet-pat Nov 24, 2023
3e25a35
Fix traversal op_endif location assignment
mainnet-pat Nov 25, 2023
3b1db55
Move randomUtxo, randomToken and randomNFT to utils
mainnet-pat Nov 25, 2023
bbe96a7
Add jest extensions
mainnet-pat Nov 25, 2023
d99b1a3
Remove reference to vars.ts from mock provider
mainnet-pat Nov 25, 2023
1a2ef79
Implement require and log tests
mainnet-pat Nov 25, 2023
ac1fbaa
meepStr -> debugStr, cleanup
mainnet-pat Nov 25, 2023
cdc945e
Lint
mainnet-pat Nov 25, 2023
4cd2978
Lint LibauthTemplate
mainnet-pat Nov 25, 2023
e7d03d8
Lint
mainnet-pat Nov 25, 2023
f38b631
Lint cashc
mainnet-pat Nov 25, 2023
60d307a
Lint utils
mainnet-pat Nov 25, 2023
ff58448
debug.bytecode is now a compact hex string
mainnet-pat Nov 26, 2023
9c6686d
Fix tests
mainnet-pat Nov 26, 2023
0379c30
Add extensive sourcemap tests, fix generate traversal issues
mainnet-pat Nov 26, 2023
0817b03
Fix some edge cases for logging data
mainnet-pat Nov 27, 2023
370c29b
Add demo testing suite to locally develop and debug CashScript contracts
mainnet-pat Nov 27, 2023
f23b2fd
Small cleanups
mainnet-pat Nov 27, 2023
05fe978
Update linter, lint
mainnet-pat Nov 27, 2023
0f3789c
Update source map tests
mainnet-pat Nov 27, 2023
f726c55
Cleanup libauth tests
mainnet-pat Nov 27, 2023
df6a902
Update documentation
mainnet-pat Nov 27, 2023
0a2cd7d
Add bitauthUri utility to Transaction class
mainnet-pat Nov 27, 2023
b3896ad
Export random utils from cashscript
mainnet-pat Nov 27, 2023
bbb0333
Lint
mainnet-pat Nov 27, 2023
5b84d0a
Add forgotten import in documentation
mainnet-pat Nov 27, 2023
6788ac9
Update versions
mainnet-pat Nov 27, 2023
8bab42d
Fix version in release notes
mainnet-pat Nov 27, 2023
9983dbf
Handle edge case of final require verify being dropped and unsuccessf…
mainnet-pat Nov 27, 2023
72c5816
Add logging of the stack contents upon debug evaluation error
mainnet-pat Nov 29, 2023
ad876fc
Lint
mainnet-pat Nov 29, 2023
d86735d
Expose some private fields to be public to avoid casting to any
mainnet-pat Dec 7, 2023
64082fb
Minor refactor of template generation, propagate p2sh20 or p2sh32 to …
mainnet-pat Dec 7, 2023
ccb7182
Finish refactor and documentation
mainnet-pat Dec 7, 2023
66aaaf9
Move demo/testing-suite to examples/testing-suite
rkalis Dec 13, 2023
4549058
Update docs for debugging tools
rkalis Dec 13, 2023
b613b99
Change version to include -next tag
rkalis Dec 13, 2023
8354f90
Fix failing tests
rkalis Dec 13, 2023
cbd3e83
Update broken link
rkalis Dec 13, 2023
b77e6df
Fix broken link again
rkalis Dec 13, 2023
4033e8f
Fix linting
rkalis Dec 20, 2023
79dd175
Refactor formatBitAuthScript util function + update tests
rkalis Jan 3, 2024
b5f74da
Rename libauth utils to bitauth-script
rkalis Jan 3, 2024
770e4fb
Update source map tests
rkalis Jan 3, 2024
3428cec
Add test case for Mecenas to source map and bitauth script fixtures
rkalis Jan 3, 2024
ad0f611
Update generation fixtures to include debug output
rkalis Jan 3, 2024
8b574db
Add AST test cases for debug messages
rkalis Jan 3, 2024
dc566a7
Move the JestExtensions file into the src directory
rkalis Jan 10, 2024
a79bb34
Bump version to 0.10.0-next.1
rkalis Jan 10, 2024
40c5757
Add DEVELOPMENT.md
rkalis Jan 10, 2024
1370c6b
Fix tests
rkalis Jan 10, 2024
591f71f
Fix interfaces import
rkalis Jan 10, 2024
61950f8
Bump version to 0.10.0-next.2
rkalis Jan 10, 2024
23f2f6f
Increase size of 'randomUtxo' for test purposes
rkalis Jan 10, 2024
112779d
Update libauth to latest stable release
rkalis Jan 18, 2024
68644f1
Merge origin/master into next (ANTLR updates)
rkalis Jan 18, 2024
5160555
Fix broken postantlr script after ANTLR updates
rkalis Jan 18, 2024
a42badd
Refactor of the ConsoleStatementNode and ConsoleParameterNode
rkalis Jan 18, 2024
97eb9a3
Update debug_messages.cash test to be a bit more complex
rkalis Jan 23, 2024
5e7263a
Extract DebugInformation type for Artifact + small changes to artifac…
rkalis Jan 23, 2024
51611b7
Rename souceMap => sourceMap
rkalis Jan 23, 2024
e9b0f97
Update LocationData / PositionHint types
rkalis Jan 23, 2024
79b35b7
Small changes
rkalis Jan 23, 2024
5fdb8f4
Update cashscript sdk fixtures to include debug data
rkalis Feb 1, 2024
ad4755b
Update sourcemap generation fixtures
rkalis Feb 1, 2024
57b4e11
Update LibauthTemplate console.log tests
rkalis Feb 23, 2024
fc3f74d
Add Transaction#getLibauthTemplate function to export libauth template
rkalis Feb 23, 2024
e471ceb
Escape multiline-style comments in debug bitauth (sourcemapped) script
rkalis Feb 23, 2024
a71004d
Restructure require statement tests
rkalis Mar 1, 2024
6163af4
Add Libauth Template generation tests and fix some issues with the ge…
rkalis Mar 1, 2024
84e52b6
Add some more edge case fixtures for Libauth Template generation
rkalis Mar 8, 2024
62f92c0
Fix bug with handling of ELSE statements + update tests accordingly
rkalis Mar 8, 2024
f96706f
Bump version to 0.10.0-next.3
rkalis Mar 19, 2024
1b66bdb
Fix failing tests
rkalis Mar 19, 2024
cc3f578
Add tests for token category equality check + update fixtures
rkalis Mar 19, 2024
e8604dc
JestExtensions + debugging test updates
rkalis Mar 26, 2024
0504e92
Fix bug in console.log statement handling
rkalis Apr 12, 2024
01ecfae
Do NOT merge separate console.log statements into a single line
rkalis Apr 12, 2024
d0594d0
Fix bugs in require statement message handling and add a bunch of tests
rkalis Apr 14, 2024
8122671
Fix bugs in JestExtensions, refactor and update tests
rkalis Apr 15, 2024
3c6b899
Fix cashc tests after debug message fixes
rkalis Apr 15, 2024
fa64c5d
Move ts-node to tsx
rkalis Apr 15, 2024
9105dbc
Bump version to 0.10.0-next.4
rkalis Apr 15, 2024
1b68e48
Fix issue with address/tokenAddress in MockNetworkProvider
rkalis Apr 25, 2024
85153a9
Fix bug in require message mapping for NULLFAIL signature checks
rkalis Apr 25, 2024
d803dc2
Extract formatBitAuthScriptForDebugging in LibauthTemplate.ts
rkalis May 1, 2024
1a442d0
Extract generateTemplateEntities in LibauthTemplate.ts
rkalis May 1, 2024
ccaf740
Extract generateTemplateScripts in LibauthTemplate.ts
rkalis May 1, 2024
79fc5d0
Extract generateTemplateScenarioParameterValues and generateTemplateS…
rkalis May 2, 2024
4b3ff47
Fix bug with double-encoding function arguments in LibauthTemplate.ts
rkalis May 2, 2024
0b69ed9
Add instructions for running tests to DEVELOPMENT.md
rkalis May 23, 2024
9467ec0
Extract generateTemplateScenarios in LibauthTemplate.ts
rkalis May 23, 2024
b05cd4d
Refactor createScenarioSourceOutputs
rkalis May 23, 2024
287e573
Refactor createScenarioTransaction
rkalis May 28, 2024
5e30b90
Move to BCH_2023_05 VM (which supports P2SH32) + rollback one of the …
rkalis May 28, 2024
3d66114
Bump version to 0.10.0-next.5
rkalis May 28, 2024
3a3badc
added failing test
mr-zwets May 29, 2024
4d6e8cb
improve text landing page
mr-zwets May 30, 2024
92b686a
full makeover to the getting-started page
mr-zwets May 30, 2024
656396e
update what is CashScript
mr-zwets May 30, 2024
6b3f04a
single place with all compiler info
mr-zwets May 30, 2024
9a0a6c5
separate page for network-provider
mr-zwets May 30, 2024
df69d9b
add more info types
mr-zwets May 30, 2024
d726562
separate debugging & testing
mr-zwets May 30, 2024
5f8f6cc
fix links to debugging page
mr-zwets May 30, 2024
8dd1efd
add to debugging guide
mr-zwets May 30, 2024
9fd45d8
improve coventants guide
mr-zwets May 30, 2024
92d6db3
Misc. fixes docs website
mr-zwets May 30, 2024
6e3ca7a
added badgers.cash to showcase
mr-zwets May 31, 2024
aa32ecb
rewrite optimization guide
mr-zwets May 31, 2024
59de8bc
remove edit button
mr-zwets May 31, 2024
0602d05
change github links docs
mr-zwets May 31, 2024
bd0f8a2
Fix require message handling edge case bug
rkalis Jun 11, 2024
619eaf8
Document 'quick rebuild' command
rkalis Jun 11, 2024
a5edbf7
Add failing test for console.log bytecode preservation
rkalis Jun 11, 2024
aa4012f
add error message incorrect number function arguments to createUnlock…
mr-zwets Jun 13, 2024
a510aaf
Fix console.log bugs
rkalis Jun 18, 2024
4d8ee07
Remove cashproof git dependency
rkalis Jun 18, 2024
f91bfa2
docs: typos and grammar (#194)
fredericAerts Jun 18, 2024
e426857
improve timelock docs
mr-zwets Jun 18, 2024
136f1b9
add the compiled code for TransferWithTimeout
mr-zwets Jun 21, 2024
53669cf
use sidebars.js instead of auto-generated sidebar
mr-zwets Jun 25, 2024
bca4580
Add *all* require statements to artifact, not only the ones with mess…
rkalis Jun 25, 2024
c760fc0
Simplify failed require errors
rkalis Jun 25, 2024
746063d
Bump version to 0.10.0-next.6
rkalis Jun 25, 2024
b26f1f2
Update development docs and skip failing test for publication
rkalis Jun 25, 2024
18b08f6
Add extra test case for P2SH20, fix bug with placeholder data & fix f…
rkalis Aug 6, 2024
55acace
Add test case for zero-encoding
rkalis Aug 6, 2024
24d77df
Support for different hashtypes / signing algorithms in unlocking par…
rkalis Aug 6, 2024
a100404
Allow cashscript/jest import instead of cashscript/dist/test/...
rkalis Aug 6, 2024
3928909
Update Bitcoin-com/cashscript references to CashScript/cashscript
rkalis Aug 6, 2024
8ded3df
Update dev dependencies
rkalis Aug 13, 2024
f9b108c
Fix several failing tests
rkalis Aug 13, 2024
95ebd52
Add eslint rule for throwing Error objects and fix two incorrect cases
rkalis Aug 13, 2024
a57af59
Simplify some failed transaction error handling
rkalis Aug 13, 2024
3c3045a
Add warning when debugging without proper debug information & remove …
rkalis Aug 13, 2024
250e329
Move and resolve some outstanding TODOs
rkalis Aug 13, 2024
0791f70
Make templates support multiple P2PKH inputs with custom signing para…
rkalis Aug 20, 2024
ae38452
Improve error messages
rkalis Aug 20, 2024
f5038e9
Fix bug in IP -> source code statement mapping and update tests/fixtures
rkalis Aug 22, 2024
55451bd
Extend debugging tests so they also cover 'Failing statement' checks
rkalis Aug 27, 2024
2888465
Update Libauth to v3 and enable checkMultiSig test in debugging tests
rkalis Aug 27, 2024
4446fc1
Mark some re-exports as 'type' so tsx doesn't complain + update examp…
rkalis Aug 27, 2024
a9954ab
Merge getLocationDataForInstructionPointer logic from require/non-req…
rkalis Aug 27, 2024
1345308
update pragma version in documentation
mr-zwets Aug 28, 2024
d50b399
add separate category to sidebar for compiler topics
mr-zwets Aug 28, 2024
089c550
fully rewrite intro section to Bitcoin Cash
mr-zwets Aug 28, 2024
4d8093e
fix broken links
mr-zwets Aug 28, 2024
361868f
change the features on the homepage
mr-zwets Aug 28, 2024
51e9fc5
rename JS SDK to TS SDK
mr-zwets Aug 29, 2024
bf6857d
Fix multiline failing statement error handling
rkalis Sep 3, 2024
d516a69
Make positionHint mandatory and update fixtures
rkalis Sep 5, 2024
d8bfa2b
Separate out ConstructorArgument and FunctionArgument (breaking)
rkalis Sep 5, 2024
f4e2a3e
Remove NodeErrorReason (breaking)
rkalis Sep 5, 2024
3022848
Support literal values for sig parameters in addition to SignatureTem…
rkalis Sep 5, 2024
9b1d858
Remove TODOs and move some of them to a GitHub issue
rkalis Sep 5, 2024
a714dc4
Add JestExtensions toFailRequire() without message + update relevant …
rkalis Sep 5, 2024
6f5f8e6
Add example for console.log + small docs changes
rkalis Sep 5, 2024
c2ab68f
remove note meep
mr-zwets Sep 6, 2024
c30e89d
move global units
mr-zwets Sep 6, 2024
4a8e33f
add docs performRequest
mr-zwets Sep 6, 2024
1264724
re-add the examples page for the SDK
mr-zwets Sep 6, 2024
24c3000
Update testing setup and network provider docs pages
rkalis Sep 10, 2024
a23b10c
Change some fields on TransactionBuilder to public
rkalis Sep 10, 2024
d0c0bd8
Update migration and release notes
rkalis Sep 10, 2024
c5731c3
Update docs
rkalis Sep 10, 2024
59162f0
Bump version to 0.10.0
rkalis Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const path = require('path');
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'import'],
extends: ['airbnb-typescript/base'],
parserOptions: {
project: path.join(__dirname, 'tsconfig.json'),
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
ecmaVersion: 2021, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
extraFileExtensions: ['.cjs'],
},
Expand Down Expand Up @@ -46,6 +46,7 @@ module.exports = {
'max-classes-per-file': 0, // Multiple classes in one file are allowed (e.g. Errors)
'@typescript-eslint/no-redeclare': 0, // I sometimes name variables an types the same
'linebreak-style': 0, // Ignore linebreak lints https://stackoverflow.com/a/43008668/1129108
'import/extensions': ['error', 'always'], // ESM requires file extensions
'import/extensions': ['error', 'ignorePackages'], // ESM requires file extensions
'@typescript-eslint/only-throw-error': 'error', // We should only throw Error objects
},
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ typings/

# DynamoDB Local files
.dynamodb/

manual-test.ts
50 changes: 49 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
We use yarn workspaces + lerna for monorepo management. So to get started, clone this repository and run `yarn` in the root directory to install all dependencies for all packages.

When updating code in one package, you can run `yarn build` in the root directory to build all packages so the changes get propagated to the other packages as well. If you're already in a package directory, you can run the following command to do so:

```bash
pushd ../.. && yarn build && popd
```

### Publishing a release

To publish a new release, we use `yarn update-version 'x.x.x'` in the root directory to bump the version before release, and then `yarn publish-all` in the root directory to publish the release. In case of a tagged release (such as `next`), we use `TESTS_USE_MOCKNET=true yarn publish-all --dist-tag <tag name>` to publish the release with the specified tag.

## cashc

### Prerequisites
Expand All @@ -24,4 +36,40 @@ When updating the grammar file in `src/grammar/CashScript.g4`, we also need to m

```bash
yarn antlr
``````
```

### Running `cashproof`

Most of the bytecode optimisations that the `cashc` compiler uses can be verified for correctness using the [`cashproof` tool](https://github.com/EyeOfPython/cashproof). This tool needs to be installed separately by installing its dependencies using `pip` and cloning its repository from GitHub.

From there, you can run `python <cashproof_path> [filenames]` to verify that the optimisations contained in these files are provably correct.

Example:
```bash
python <cashproof_path> packages/cashc/test/cashproof/0.1.2=0.2.0.equiv
```

Note that if you want to run `cashproof` on the "main" CashScript optimisations file, you need to first extract the optimisations from the `cashc` compiler and save them in a separate file. This can be done using the following commands:

```bash
cp packages/utils/src/cashproof-optimisations.ts opt.equiv && sed -i '' '/`/d' opt.equiv
python <cashproof_path> opt.equiv
```

## cashscript

### Running tests

By default, running tests in the `cashscript` package uses chipnet contracts, which requires the test accounts to have some chipnet BCH. To run the tests against a local "mock network", you can use the `TESTS_USE_MOCKNET` environment variable.

```bash
# Run all tests using the mock network
TESTS_USE_MOCKNET=true yarn test
```

To run specific tests, you can use the `-t` flag to match the name mentioned in the `it` or `describe` block:

```bash
# Run all tests in the 'Transaction Builder' describe block (test/e2e/transaction-builder/TransactionBuilder.test.ts)
yarn test -t 'Transaction Builder'
```
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# CashScript

[![Build Status](https://travis-ci.org/Bitcoin-com/cashscript.svg)](https://travis-ci.org/Bitcoin-com/cashscript)
[![Coverage Status](https://img.shields.io/codecov/c/github/Bitcoin-com/cashscript.svg)](https://codecov.io/gh/Bitcoin-com/cashscript/)
[![Build Status](https://travis-ci.org/CashScript/cashscript.svg)](https://travis-ci.org/CashScript/cashscript)
[![Coverage Status](https://img.shields.io/codecov/c/github/CashScript/cashscript.svg)](https://codecov.io/gh/CashScript/cashscript/)
[![NPM Version](https://img.shields.io/npm/v/cashscript.svg)](https://www.npmjs.com/package/cashscript)
[![NPM Monthly Downloads](https://img.shields.io/npm/dm/cashscript.svg)](https://www.npmjs.com/package/cashscript)
[![NPM License](https://img.shields.io/npm/l/cashscript.svg)](https://www.npmjs.com/package/cashscript)

CashScript is a high-level programming language for smart contracts on Bitcoin Cash. It offers a strong abstraction layer over Bitcoin Cash' native virtual machine, Bitcoin Script. Its syntax is based on Ethereum's smart contract language Solidity, but its functionality is very different since smart contracts on Bitcoin Cash differ greatly from smart contracts on Ethereum. For a detailed comparison of them, refer to the blog post [_Smart Contracts on Ethereum, Bitcoin and Bitcoin Cash_](https://kalis.me/smart-contracts-eth-btc-bch/).

This repository contains the code for the CashScript compiler & command line tool under [`packages/cashc/`](/packages/cashc). This repository also contains the code for the CashScript JavaScript SDK under [`packages/cashscript/`](/packages/cashscript). The source code of the [CashScript.org](https://cashscript.org) website is included under [`website/`](/website). Visit the website for a detailed [Documentation](https://cashscript.org/docs/) on the CashScript language and SDK.
This repository contains the code for the CashScript compiler & command line tool under [`packages/cashc/`](/packages/cashc). This repository also contains the code for the CashScript TypeScript SDK under [`packages/cashscript/`](/packages/cashscript). The source code of the [CashScript.org](https://cashscript.org) website is included under [`website/`](/website). Visit the website for a detailed [Documentation](https://cashscript.org/docs/) on the CashScript language and SDK.

## The CashScript Language

CashScript is a high-level language that allows you to write Bitcoin Cash smart contracts in a straightforward and familiar way. Its syntax is inspired by Ethereum's Solidity language, but its functionality is different since the underlying systems have very different fundamentals. See the [language documentation](https://cashscript.org/docs/language/) for a full reference of the language.

## The CashScript Compiler

CashScript features a compiler as a standalone command line tool, called `cashc`. It can be installed through npm and used to compile `.cash` files into `.json` artifact files. These artifact files can be imported into the CashScript JavaScript SDK (or other SDKs in the future). The `cashc` NPM package can also be imported inside JavaScript files to compile `.cash` files without using the command line tool.
CashScript features a compiler as a standalone command line tool, called `cashc`. It can be installed through npm and used to compile `.cash` files into `.json` artifact files. These artifact files can be imported into the CashScript TypeScript SDK (or other SDKs in the future). The `cashc` NPM package can also be imported inside JavaScript files to compile `.cash` files without using the command line tool.

### Installation

Expand Down Expand Up @@ -94,16 +94,16 @@ The "Hello World" of CashScript contracts is defining the P2PKH pattern inside a
To run the examples, clone this repository and navigate to the `examples/` directory. Since the examples depend on the SDK, be sure to run `npm install` or `yarn` inside the `examples/` directory, which installs all required packages.

```bash
git clone git@github.com:Bitcoin-com/cashscript.git
git clone git@github.com:CashScript/cashscript.git
cd cashscript/examples
npm install
```

All `.ts` files in the [`examples/`](/examples) directory can then be executed with `ts-node-esm`.
All `.ts` files in the [`examples/`](/examples) directory can then be executed with `tsx`.

```bash
npm install -g ts-node
ts-node-esm p2pkh.ts
npm install -g tsx
tsx p2pkh.ts
```

All `.js` files can be executed with `node`.
Expand Down
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ cd cashscript/examples
yarn
```

All `.ts` files can then be executed with `ts-node-esm`.
All `.ts` files can then be executed with `tsx`.

```bash
npm install -g ts-node
ts-node-esm p2pkh.ts
npm install -g tsx
tsx p2pkh.ts
```

All `.js` files can be executed with `node`.
Expand Down
2 changes: 1 addition & 1 deletion examples/announcement.cash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma cashscript ^0.9.0;
pragma cashscript ^0.10.0;

/* This is a contract showcasing covenants outside of regular transactional use.
* It enforces the contract to make an "announcement" on Memo.cash, and send the
Expand Down
4 changes: 2 additions & 2 deletions examples/common-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import bip39 from 'bip39';

// Generate entropy from BIP39 mnemonic phrase and initialise a root HD-wallet node
const seed = await bip39.mnemonicToSeed('CashScript Examples');
const rootNode = deriveHdPrivateNodeFromSeed(seed, true);
const rootNode = deriveHdPrivateNodeFromSeed(seed, { assumeValidity: true, throwErrors: true });
const baseDerivationPath = "m/44'/145'/0'/0";

// Derive Alice's private key, public key, public key hash and address
Expand All @@ -20,4 +20,4 @@ if (typeof aliceNode === 'string') throw new Error();
export const alicePub = secp256k1.derivePublicKeyCompressed(aliceNode.privateKey);
export const alicePriv = aliceNode.privateKey;
export const alicePkh = hash160(alicePub);
export const aliceAddress = encodeCashAddress('bchtest', 'p2pkh', alicePkh);
export const aliceAddress = encodeCashAddress({ prefix: 'bchtest', type: 'p2pkh', payload: alicePkh, throwErrors: true }).address;
8 changes: 4 additions & 4 deletions examples/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PriceOracle } from './PriceOracle.js';

// Generate entropy from BIP39 mnemonic phrase and initialise a root HD-wallet node
const seed = await bip39.mnemonicToSeed('CashScript Examples');
const rootNode = deriveHdPrivateNodeFromSeed(seed, true);
const rootNode = deriveHdPrivateNodeFromSeed(seed, { assumeValidity: true, throwErrors: true });
const baseDerivationPath = "m/44'/145'/0'/0";

// Derive Alice's private key, public key, public key hash and address
Expand All @@ -19,15 +19,15 @@ if (typeof aliceNode === 'string') throw new Error();
export const alicePub = secp256k1.derivePublicKeyCompressed(aliceNode.privateKey) as Uint8Array;
export const alicePriv = aliceNode.privateKey;
export const alicePkh = hash160(alicePub);
export const aliceAddress = encodeCashAddress('bchtest', 'p2pkhWithTokens', alicePkh);
export const aliceAddress = encodeCashAddress({ prefix: 'bchtest', type: 'p2pkhWithTokens', payload: alicePkh, throwErrors: true }).address;

// Derive Bob's private key, public key, public key hash and address
const bobNode = deriveHdPath(rootNode, `${baseDerivationPath}/1`);
if (typeof bobNode === 'string') throw new Error();
export const bobPub = secp256k1.derivePublicKeyCompressed(bobNode.privateKey) as Uint8Array;
export const bobPriv = bobNode.privateKey;
export const bobPkh = hash160(bobPub);
export const bobAddress = encodeCashAddress('bchtest', 'p2pkhWithTokens', bobPkh);
export const bobAddress = encodeCashAddress({ prefix: 'bchtest', type: 'p2pkhWithTokens', payload: bobPkh, throwErrors: true }).address;

// Initialise a price oracle with a private key
const oracleNode = deriveHdPath(rootNode, `${baseDerivationPath}/2`);
Expand All @@ -36,4 +36,4 @@ export const oraclePub = secp256k1.derivePublicKeyCompressed(oracleNode.privateK
export const oraclePriv = oracleNode.privateKey;
export const oracle = new PriceOracle(oracleNode.privateKey);
export const oraclePkh = hash160(oraclePub);
export const oracleAddress = encodeCashAddress('bchtest', 'p2pkhWithTokens', oraclePkh);
export const oracleAddress = encodeCashAddress({ prefix: 'bchtest', type: 'p2pkhWithTokens', payload: oraclePkh, throwErrors: true }).address;
2 changes: 1 addition & 1 deletion examples/hodl_vault.cash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma cashscript ^0.9.0;
pragma cashscript ^0.10.0;

// This contract forces HODLing until a certain price target has been reached
// A minimum block is provided to ensure that oracle price entries from before this block are disregarded
Expand Down
2 changes: 1 addition & 1 deletion examples/mecenas.cash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma cashscript ^0.9.0;
pragma cashscript ^0.10.0;

/* This is an unofficial CashScript port of Licho's Mecenas contract. It is
* not compatible with Licho's EC plugin, but rather meant as a demonstration
Expand Down
2 changes: 1 addition & 1 deletion examples/mecenas_locktime.cash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma cashscript ^0.9.0;
pragma cashscript ^0.10.0;

// This is an experimental contract for a more "streaming" Mecenas experience
// Completely untested, just a concept
Expand Down
2 changes: 1 addition & 1 deletion examples/p2pkh.cash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma cashscript ^0.9.0;
pragma cashscript ^0.10.0;

contract P2PKH(bytes20 pkh) {
// Require pk to match stored pkh and signature to match
Expand Down
12 changes: 8 additions & 4 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"name": "cashscript-examples",
"private": true,
"version": "0.9.3",
"version": "0.10.0",
"description": "Usage examples of the CashScript SDK",
"main": "p2pkh.js",
"type": "module",
"author": "Rosco Kalis <rosco@bitcoin.com>",
"license": "MIT",
"scripts": {
"lint": "eslint . --ext .ts --ignore-path ../.eslintignore"
},
"dependencies": {
"@bitauth/libauth": "^2.0.0-alpha.8",
"@bitauth/libauth": "^3.0.0",
"@types/node": "^12.7.8",
"bip39": "^3.0.4",
"cashc": "^0.9.3",
"cashscript": "^0.9.3",
"cashc": "^0.10.0",
"cashscript": "^0.10.0",
"eslint": "^8.56.0",
"typescript": "^4.9.5"
}
}
47 changes: 47 additions & 0 deletions examples/testing-suite/artifacts/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"contractName": "Example",
"constructorInputs": [],
"abi": [
{
"name": "test",
"inputs": [
{
"name": "value",
"type": "int"
}
]
}
],
"bytecode": "OP_1 OP_NUMEQUAL",
"source": "contract Example() {\n function test(int value) {\n console.log(value, \"test\");\n require(value == 1, \"Wrong value passed\");\n }\n}\n",
"debug": {
"bytecode": "007a519c",
"sourceMap": "4:12:4:17;;:21::22;:12:::1",
"logs": [
{
"ip": 0,
"line": 3,
"data": [
{
"stackIndex": 0,
"type": "int",
"ip": 0
},
"test"
]
}
],
"requires": [
{
"ip": 4,
"line": 4,
"message": "Wrong value passed"
}
]
},
"compiler": {
"name": "cashc",
"version": "0.10.0"
},
"updatedAt": "2024-09-10T09:55:42.448Z"
}
6 changes: 6 additions & 0 deletions examples/testing-suite/contracts/example.cash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
contract Example() {
function test(int value) {
console.log(value, "test");
require(value == 1, "Wrong value passed");
}
}
6 changes: 6 additions & 0 deletions examples/testing-suite/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
transform: {},
roots: ['./dist-test'],
testEnvironment: 'jest-environment-node',
setupFilesAfterEnv: ['./jest.setup.js'],
};
8 changes: 8 additions & 0 deletions examples/testing-suite/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { jest } from '@jest/globals';
import { inspect } from 'util';
inspect.defaultOptions.depth = 10;

jest.setTimeout(50000);

globalThis.jest = jest;

39 changes: 39 additions & 0 deletions examples/testing-suite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "testing-suite",
"version": "0.10.0",
"description": "Example project to develop and test CashScript contracts",
"main": "index.js",
"type": "module",
"author": "mainnet-pat",
"license": "MIT",
"private": true,
"directories": {
"lib": "src",
"test": "test"
},
"scripts": {
"build": "yarn clean && yarn compile",
"build:test": "yarn clean:test && yarn compile:test",
"clean": "rm -rf ./dist",
"clean:test": "rm -rf ./dist-test",
"compile": "tsc -p tsconfig.json && tsx tasks/index.ts compile",
"compile:test": "tsc -p tsconfig.test.json && tsx tasks/index.ts compile",
"lint": "eslint . --ext .ts --ignore-path ../../.eslintignore",
"prepare": "yarn build",
"prepublishOnly": "yarn test && yarn lint",
"pretest": "yarn build:test",
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"
},
"dependencies": {
"cashc": "^0.10.0",
"cashscript": "^0.10.0",
"url-join": "^5.0.0"
},
"devDependencies": {
"@jest/globals": "^29.4.1",
"@types/jest": "^29.4.1",
"jest": "^29.4.1",
"tsx": "^4.7.2",
"typescript": "^4.9.5"
}
}
Empty file.
26 changes: 26 additions & 0 deletions examples/testing-suite/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { compileString } from 'cashc';
import fs from 'fs';
import { URL } from 'url';
import urlJoin from 'url-join';

export const compile = (): void => {
const directory = new URL('../contracts', import.meta.url);
const result = fs.readdirSync(directory)
.filter((fn) => fn.endsWith('.cash'))
.map((fn) => ({ fn, contents: fs.readFileSync(new URL(urlJoin(directory.toString(), fn)), { encoding: 'utf-8' }) }));

result.forEach(({ fn, contents }) => {
const artifact = compileString(contents);

fs.writeFileSync(new URL(`../artifacts/${fn.replace('.cash', '.json')}`, import.meta.url), JSON.stringify(artifact, null, 2));
});
};

switch (process.argv[2]) {
case 'compile':
compile();
break;
default:
console.log('Unknown task');
break;
}
Loading