-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from CashScript/next
- Loading branch information
Showing
155 changed files
with
12,095 additions
and
2,746 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,3 +105,5 @@ typings/ | |
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
manual-test.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
@@ -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 [email protected]:Bitcoin-com/cashscript.git | ||
git clone [email protected]: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`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]>", | ||
"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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.