Skip to content

Commit 3aa7fd9

Browse files
committedNov 9, 2024
Update README
1 parent d155c48 commit 3aa7fd9

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed
 

‎README.md

+25-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
# bitcoin-script
1+
# Bitvm Bitcoin Script
22

3-
[![Rust](https://github.com/mappum/rust-bitcoin-script/workflows/Rust/badge.svg)](https://github.com/mappum/rust-bitcoin-script/actions?query=workflow%3ARust)
4-
[![crates.io](https://img.shields.io/crates/v/bitcoin-script.svg)](https://crates.io/crates/bitcoin-script)
5-
[![docs.rs](https://docs.rs/bitcoin-script/badge.svg)](https://docs.rs/bitcoin-script)
6-
7-
**Bitcoin scripts inline in Rust.**
8-
9-
---
3+
Utilities used in the official [BitVM](`https://github.com/BitVM/BitVM`) implementation to generate Bitcoin Script. Heavily inspired by [rust-bitcoin-script's inline macro](`https://github.com/mappum/rust-bitcoin-script`).
104

115
## Usage
126

13-
This crate exports a `script!` macro which can be used to build Bitcoin scripts. The macro returns the [`Script`](https://docs.rs/bitcoin/latest/bitcoin/struct.ScriptBuf.html) type from the [`bitcoin`](https://github.com/rust-bitcoin/rust-bitcoin) crate.
7+
This crate exports a `script!` macro which can be used to build structured Bitcoin scripts and compiled to the [`Script`](https://docs.rs/bitcoin/latest/bitcoin/struct.ScriptBuf.html) type from the [`bitcoin`](https://github.com/rust-bitcoin/rust-bitcoin) crate.
148

159
**Example:**
1610

1711
```rust
18-
#![feature(proc_macro_hygiene)]
19-
2012
use bitcoin_script::bitcoin_script;
2113

2214
let htlc_script = script! {
@@ -28,6 +20,8 @@ let htlc_script = script! {
2820
OP_EQUALVERIFY
2921
OP_CHECKSIG
3022
};
23+
24+
let script_buf = htlc_script.compile();
3125
```
3226

3327
### Syntax
@@ -77,6 +71,7 @@ Rust expressions of the following types are supported:
7771
- [`bitcoin::PublicKey`](https://docs.rs/bitcoin/latest/bitcoin/struct.PublicKey.html)
7872
- [`bitcoin::XOnlyPublicKey`](https://docs.rs/bitcoin/latest/bitcoin/struct.XOnlyPublicKey.html)
7973
- [`bitcoin::ScriptBuf`](https://docs.rs/bitcoin/latest/bitcoin/struct.ScriptBuf.html)
74+
- `StructuredScript`
8075

8176
```rust
8277
let bytes = vec![1, 2, 3];
@@ -90,5 +85,22 @@ let script = script! {
9085
};
9186
```
9287

93-
### Optimality
94-
Obsolete Opcodes are automatically removed when using the `optimal_opcodes` branch. E.g. a sequence of `OP_0 OP_ROLL` will be optimized away.
88+
#### Conditional Scipt Generation
89+
90+
For-loops and if-else-statements are supported inside the script and will be unrolled when the scripts are generated.
91+
92+
```rust
93+
let loop_count = 10;
94+
95+
let script = script! {
96+
for i in 0..loop_count {
97+
if i % 2 == 0 {
98+
OP_ADD
99+
} else {
100+
OP_DUP
101+
OP_ADD
102+
}
103+
}
104+
};
105+
106+
```

0 commit comments

Comments
 (0)