Skip to content

Commit 986c8fb

Browse files
committed
Small docs updates + improve 1 test
1 parent b80d4ca commit 986c8fb

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
contract Test(sig signature) {
2+
function spend() {
3+
// Assume Schnorr
4+
bytes hashtype1 = signature.split(64)[1];
5+
bytes1 hashtype2 = signature.slice(64, 65);
6+
require(hashtype1 == 0x01);
7+
require(hashtype2 == 0x01);
8+
}
9+
}

packages/cashc/test/valid-contract-files/split_signature.cash

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

website/docs/compiler/grammar.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ assignStatement
7474
;
7575
7676
timeOpStatement
77-
: 'require' '(' TxVar '>=' expression (',' StringLiteral)? ')' ';'
77+
: 'require' '(' TxVar '>=' expression (',' requireMessage)? ')' ';'
7878
;
7979
8080
requireStatement
81-
: 'require' '(' expression (',' StringLiteral)? ')' ';'
81+
: 'require' '(' expression (',' requireMessage)? ')' ';'
8282
;
8383
8484
ifStatement
@@ -89,6 +89,10 @@ consoleStatement
8989
: 'console.log' consoleParameterList ';'
9090
;
9191
92+
requireMessage
93+
: StringLiteral
94+
;
95+
9296
consoleParameter
9397
: Identifier
9498
| literal
@@ -116,6 +120,7 @@ expression
116120
| scope='tx.inputs' '[' expression ']' op=('.value' | '.lockingBytecode' | '.outpointTransactionHash' | '.outpointIndex' | '.unlockingBytecode' | '.sequenceNumber' | '.tokenCategory' | '.nftCommitment' | '.tokenAmount') # UnaryIntrospectionOp
117121
| expression op=('.reverse()' | '.length') # UnaryOp
118122
| left=expression op='.split' '(' right=expression ')' # BinaryOp
123+
| element=expression '.slice' '(' start=expression ',' end=expression ')' # Slice
119124
| op=('!' | '-') expression # UnaryOp
120125
| left=expression op=('*' | '/' | '%') right=expression # BinaryOp
121126
| left=expression op=('+' | '-') right=expression # BinaryOp

website/docs/language/types.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ The script will fail if `split()` or `slice()` is called with an index that is o
101101
```solidity
102102
bytes mintingCapability = 0x02;
103103
bytes noCapability = 0x;
104+
105+
bytes2 data = 0x12345678.slice(1, 3); // 0x3456
104106
```
105107

106108
## Bytes types with semantic meaning
@@ -141,8 +143,8 @@ checkMultisig([sig1, sig2], [pk1, pk2, pk3]);
141143
Tuples are the type that is returned when calling the `split` member function on a `string` or `bytes` type. Their first or second element can be accessed through an indexing syntax similar to other languages:
142144

143145
```solidity
144-
string question = "What is Bitcoin Cash?";
145-
string answer = question.split(15)[0].split(8)[1]; // Answer is "Cash"
146+
string bitcoinCash = "Bitcoin Cash";
147+
string cash = bitcoinCash.split(8)[1];
146148
```
147149

148150
:::note
@@ -152,8 +154,8 @@ It is not supported to use a variable for the tupleIndex. Instead you can assign
152154
It is also possible to assign both sides of the tuple at once with a destructuring syntax:
153155

154156
```solidity
155-
string hello, string world = "Hello World".split(5);
156-
require(hello + "world" == "Hello " + world);
157+
string hello, string world = "Hello World".split(6);
158+
require(hello + "World" == "Hello " + world);
157159
```
158160

159161
## Type Casting

website/docs/releases/release-notes.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,28 @@ title: Release Notes
66

77
#### cashc compiler
88
- :sparkles: Add `.slice(start, end)` operator for bytes and strings.
9-
- :sparkles: Add bounded bytes typing and bounds checking for `.split()` (includes checking for negative indices)
10-
- :racehorse: Add optimisation for `.slice(0, x)` and `.slice(x, y.length)` (also applies to `.split(0)[1]`)
11-
- :bug: Disallow incorrect bounded bytes typing when using `.split()`
9+
- :sparkles: Add bounded bytes typing and bounds checking for `.split()` (includes checking for negative indices).
10+
- :racehorse: Add optimisation for `.slice(0, x)` and `.slice(x, y.length)` (also applies to `.split(0)[1]`).
11+
- :bug: Disallow incorrect bounded bytes typing when using `.split()`.
1212

1313
#### CashScript SDK
14-
- :bug: Fix bug with where `ElectrumNetworkProvider` would disconnect in browser on visibility change of the page
14+
- :bug: Fix bug with where `ElectrumNetworkProvider` would disconnect in browser on visibility change of the page.
1515

1616
## v0.11.2
1717

1818
#### CashScript SDK
19-
- :bug: Fix bug with new `generateWcTransactionObject()` throwing when using `placeholderP2PKHUnlocker()`
19+
- :bug: Fix bug with new `generateWcTransactionObject()` throwing when using `placeholderP2PKHUnlocker()`.
2020

2121
## v0.11.1
2222

2323
#### CashScript SDK
2424
- :sparkles: Add `generateWcTransactionObject()` method to `TransactionBuilder` to generate a `WcTransactionObject` that can be used to sign a transaction with a WalletConnect client.
2525
- :sparkles: Add `placeholderSignature()`, `placeholderPublicKey()` and `placeholderP2PKHUnlocker()` helper functions to the SDK for WalletConnect usage.
2626

27+
---
28+
29+
https://x.com/CashScriptBCH/status/1942513305420968238
30+
2731
## v0.11.0
2832

2933
This update adds CashScript support for the new BCH 2025 network upgrade. To read more about the upgrade, see [this blog post](https://blog.bitjson.com/2025-chips/).
@@ -55,6 +59,10 @@ This release also contains several breaking changes, please refer to the [migrat
5559
- :bug: Fix bug where `JestExtensions` `expect().toLog()` would detect logs from different tests.
5660
- :bug: Fix bug where certain edge cases in require statements caused the `FailedRequireError` message to be slightly different from the original error message.
5761

62+
---
63+
64+
https://x.com/CashScriptBCH/status/1935662184865890325
65+
5866
#### @cashscript/utils
5967
- :boom: **BREAKING**: Remove `importArtifact` and `exportArtifact` helper functions. If you want to import or export artifacts, use `'fs'` to read and write files directly.
6068

0 commit comments

Comments
 (0)