Skip to content

Commit 4119474

Browse files
committed
Add support for v0.8.0
- Update Antlr grammar - Add token properties to inputs and outputs - Remove 'OutputX' in favour of 'LockingBytecodeX' - Remove 'Compilation' functionality due to ESM incompatibilties - Small fixes (highlight '*' and '0x' in code) - Update examples
1 parent c73c81a commit 4119474

25 files changed

Lines changed: 5837 additions & 5864 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
client/server
44
.vscode-test
55
*.vsix
6-
examples/*.json
6+
examples/*.json
7+
**/.antlr

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ A special thank you to [vscode-solidity](https://github.com/juanfranblanco/vscod
1414
- Auto-Completion
1515
- Snippets
1616
- Linting
17-
- Contract Compilation
1817

1918
## Development Instructions
2019

@@ -23,19 +22,19 @@ Press **F5** or click the "**Compile Contract**" button in the top right. A json
2322
Clone the project
2423

2524
```
26-
git clone https://github.com/nathanielCherian/vscode-cashscript
25+
git clone https://github.com/nathanielCherian/vscode-cashscript
2726
```
2827

2928
Install Dependencies
3029

3130
```
32-
cd vscode-cashscript && npm i
31+
cd vscode-cashscript && npm i
3332
```
3433

3534
Open the project in vscode.
3635

3736
```
38-
code .
37+
code .
3938
```
4039

4140
Press F5 anywhere to start the test window, open the examples folder to test out any '.cash' file. All relevent files are located within the /src directory.

examples/anyhedge.cash

Lines changed: 96 additions & 194 deletions
Large diffs are not rendered by default.

examples/anyhedge_min.cash

Lines changed: 0 additions & 104 deletions
This file was deleted.

examples/locktime.cash

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/may-2022.cash

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pragma cashscript ^0.7.0;
2+
3+
contract P2PKH() {
4+
function spend() {
5+
bytes2 left, bytes2 right = 0x123456.split(2);
6+
int constant c = 5;
7+
require(left == right);
8+
require(c * 2 == 2);
9+
10+
require(this.activeBytecode == 0x);
11+
require(this.activeInputIndex == 0);
12+
require(tx.version == 2);
13+
require(tx.locktime == 1);
14+
require(tx.inputs.length == 1);
15+
require(tx.inputs[i].value == 1);
16+
require(tx.inputs[i].lockingBytecode == 0x);
17+
require(tx.inputs[i].unlockingBytecode == 0x);
18+
require(tx.inputs[i].outpointTransactionHash == 0x);
19+
require(tx.inputs[i].outpointIndex == 1);
20+
require(tx.inputs[i].sequenceNumber == 1);
21+
22+
require(tx.outputs[i].value == 1);
23+
require(tx.outputs.length == 1);
24+
require(tx.outputs[i].lockingBytecode == 0x);
25+
}
26+
}

examples/may-2023.cash

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pragma cashscript ^0.7.0;
2+
3+
contract P2PKH() {
4+
function spend() {
5+
require(tx.inputs[0].tokenCategory == bytes32(0));
6+
require(tx.inputs[0].nftCommitment == bytes32(0));
7+
require(tx.inputs[0].tokenAmount == 0);
8+
9+
require(tx.outputs[0].tokenCategory == bytes32(0));
10+
require(tx.outputs[0].nftCommitment == bytes32(0));
11+
require(tx.outputs[0].tokenAmount == 0);
12+
13+
require(tx.outputs[0].lockingBytecode == new LockingBytecodeP2SH32(bytes32(0)));
14+
}
15+
}

examples/mecenas.cash

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pragma cashscript ^0.8.0;
2+
3+
/* This is an unofficial CashScript port of Licho's Mecenas contract. It is
4+
* not compatible with Licho's EC plugin, but rather meant as a demonstration
5+
* of covenants in CashScript.
6+
* The time checking has been removed so it can be tested without time requirements.
7+
*/
8+
contract Mecenas(bytes20 recipient, bytes20 funder, int pledge/*, int period */) {
9+
function receive() {
10+
// require(tx.age >= period);
11+
12+
// Check that the first output sends to the recipient
13+
require(tx.outputs[0].lockingBytecode == new LockingBytecodeP2PKH(recipient));
14+
15+
int minerFee = 1000;
16+
int currentValue = tx.inputs[this.activeInputIndex].value;
17+
int changeValue = currentValue - pledge - minerFee;
18+
19+
// If there is not enough left for *another* pledge after this one, we send the remainder to the recipient
20+
// Otherwise we send the remainder to the recipient and the change back to the contract
21+
if (changeValue <= pledge + minerFee) {
22+
require(tx.outputs[0].value == currentValue - minerFee);
23+
} else {
24+
require(tx.outputs[0].value == pledge);
25+
require(tx.outputs[1].lockingBytecode == tx.inputs[this.activeInputIndex].lockingBytecode);
26+
require(tx.outputs[1].value == changeValue);
27+
}
28+
}
29+
30+
function reclaim(pubkey pk, sig s) {
31+
require(hash160(pk) == funder);
32+
require(checkSig(s, pk));
33+
}
34+
}

examples/next.cash

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/p2pkh.cash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ pragma cashscript ^0.6.0;
22

33
contract P2PKH(bytes20 pkh) {
44
function spend(pubkey pk, sig s) {
5-
byte m = 0x01;
5+
byte m = 0x01;
66
require(checkSig(s, pk));
77
require(hash160(pk) == pkh);
88
require(int(m) == 2);
99
}
10-
}
10+
}

0 commit comments

Comments
 (0)