Skip to content

Commit 76c593a

Browse files
committed
PoC of schema
1 parent 7be3c3e commit 76c593a

78 files changed

Lines changed: 5931 additions & 8242 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 3273 additions & 631 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[workspace]
22
resolver = "3"
33
members = [
4-
"crates/*"
4+
"crates/cli",
5+
"crates/contracts",
6+
"crates/wallet-abi",
57
]
68

79
[workspace.package]
@@ -21,7 +23,10 @@ tracing = { version = "0.1.41" }
2123
minreq = { version = "2.14.1", features = ["https", "json-using-serde"]}
2224

2325
simplicityhl = { version = "0.4.0" }
24-
simplicityhl-core = { version = "0.4.2", features = ["encoding"] }
2526

2627
[patch.crates-io]
2728
simplicity-sys = { git = "https://github.com/BlockstreamResearch/rust-simplicity", tag = "simplicity-sys-0.6.1" }
29+
lwk_common = { git = "https://github.com/Blockstream/lwk", rev = "4074c527fcc1268eb26953af397eecc6c1444293", package = "lwk_common" }
30+
lwk_signer = { git = "https://github.com/Blockstream/lwk", rev = "4074c527fcc1268eb26953af397eecc6c1444293", package = "lwk_signer" }
31+
lwk_simplicity = { git = "https://github.com/Blockstream/lwk", rev = "4074c527fcc1268eb26953af397eecc6c1444293", package = "lwk_simplicity" }
32+
lwk_wollet = { git = "https://github.com/Blockstream/lwk", rev = "4074c527fcc1268eb26953af397eecc6c1444293", package = "lwk_wollet" }

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ The only crate published to crates.io is `simplicity-contracts`, so read its [RE
88

99
If you are new to contract development with Simplicity HL, below you will find a step-by-step workflow for how a contract can be developed, deployed, and used.
1010

11-
Everything starts with the actual Simplicity HL code. See the [.simf files](crates/contracts/src), especially the [Options contract](crates/contracts/src/options/source_simf/options.simf) as the most structured example. Check the issues referenced in the contract for better understanding of development implications.
11+
Everything starts with the actual Simplicity HL code. See the [.simf files](crates/contracts/src), especially the [Options contract](crates/contracts/src/finance/options/source_simf/options.simf) as the most structured example. Check the issues referenced in the contract for better understanding of development implications.
1212

1313
You can use tools like [`hal-simplicity`](https://github.com/BlockstreamResearch/hal-simplicity) for ad-hoc interaction and manual testing.
1414

15-
If you want to build an application or service around your new contract, take a look at the relevant builders of arguments and witness. See the [Options contract](crates/contracts/src/options/mod.rs) for how to write Rust functions to build those — it is well tested.
15+
If you want to build an application or service around your new contract, take a look at the relevant builders of arguments and witness. See the [Options contract](crates/contracts/src/finance/options/mod.rs) for how to write Rust functions to build those.
1616

17-
The next step after writing helper functions to build args and witness is to do actual testing. Again, see [mod.rs](crates/contracts/src/options/mod.rs) as the best example.
18-
19-
Here you could also take a look at how relevant SDK functions in [options](crates/contracts/src/sdk/options) are structured, and what their responsibilities are.
17+
The next step after writing helper functions to build args and witness is to do actual testing. Again, see [mod.rs](crates/contracts/src/finance/options/mod.rs) as the best example.
2018

2119
The last step is actual transaction publishing on the chain. This part can be found in the [CLI README](crates/cli/README.md).
2220

@@ -28,8 +26,8 @@ Though this repository provides only examples, and because the basic Simplicity
2826

2927
## Important Concepts
3028

31-
It is recommended to study the [options.simf](crates/contracts/src/options/source_simf/options.simf) and related issues on GitHub to understand better how to write such contracts securely.
29+
It is recommended to study the [options.simf](crates/contracts/src/finance/options/source_simf/options.simf) and related issues on GitHub to understand better how to write such contracts securely.
3230

33-
You can see how to use the storage for 32 bytes in the [bytes32_tr_storage.simf](crates/contracts/src/bytes32_tr_storage/source_simf/bytes32_tr_storage.simf) file.
34-
For a more general case, see the [array_tr_storage.simf](crates/contracts/src/array_tr_storage/source_simf/array_tr_storage.simf) file.
35-
You can find a more detailed explanation of how it works in the first file.
31+
You can see how to use the storage for 32 bytes in the [bytes32_tr_storage.simf](crates/contracts/src/state_management/bytes32_tr_storage/source_simf/bytes32_tr_storage.simf) file.
32+
For a more general case, see the [array_tr_storage.simf](crates/contracts/src/state_management/array_tr_storage/source_simf/array_tr_storage.simf) file.
33+
You can find a more detailed explanation of how it works in the first file.

crates/cli/src/modules/paths.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub fn wallet_data_root() -> std::path::PathBuf {
2+
std::env::var_os("SIMPLICITY_CLI_WALLET_DATA_DIR").map_or_else(
3+
|| std::path::PathBuf::from(".cache/wallet"),
4+
std::path::PathBuf::from,
5+
)
6+
}

crates/contracts/Cargo.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ keywords = ["simplicity", "liquid", "bitcoin", "elements", "contracts"]
1010
categories = ["cryptography::cryptocurrencies"]
1111

1212
[features]
13-
default = ["sdk-basic", "finance-options", "finance-dcd", "finance-option-offer", "simple-storage", "bytes32-tr-storage", "array-tr-storage", "smt-storage"]
14-
sdk-basic = []
13+
default = ["finance-options", "finance-dcd", "finance-option-offer", "simple-storage", "bytes32-tr-storage", "array-tr-storage", "smt-storage"]
1514
finance-options = []
1615
finance-dcd = []
1716
finance-option-offer = []
@@ -28,14 +27,14 @@ bincode = "2.0.1"
2827

2928
thiserror = "2"
3029

31-
ring = { workspace = true }
32-
sha2 = { workspace = true }
33-
3430
hex = { workspace = true }
3531

3632
simplicityhl = { workspace = true }
37-
38-
simplicityhl-core = { workspace = true }
33+
wallet-abi = { path = "../wallet-abi" }
34+
serde_json = "1"
35+
serde = { version = "1", features = ["derive"] }
3936

4037
[dev-dependencies]
41-
anyhow = "1"
38+
anyhow = "1"
39+
bitcoincore-rpc = "0.19.0"
40+
lwk_test_util = { git = "https://github.com/Blockstream/lwk", rev = "4074c527fcc1268eb26953af397eecc6c1444293", package = "lwk_test_util" }

crates/contracts/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# Simplicity HL Core -- Contracts
1+
# Simplicity Contracts
22

33
This crate is a collection of contracts showcasing core possibilities of [Elements](https://docs.rs/elements) and [Simplicity HL](https://github.com/BlockstreamResearch/simfony).
44

5-
Here you will find Simplicity HL implementations of [Options](https://blockstream.com/assets/downloads/pdf/options-whitepaper.pdf) (see [options](src/options)), Dual Currency Deposit Contract (see [dcd](src/dual_currency_deposit)), and more.
5+
Here you will find Simplicity HL implementations of [Options](https://blockstream.com/assets/downloads/pdf/options-whitepaper.pdf) (see [finance/options](src/finance/options)), Dual Currency Deposit Contract (see [finance/dcd](src/finance/dcd)), storage contracts, and more.
66

7-
The module that stands out is [`sdk`](src/sdk). This module does not contain contract source code; instead, it provides builder functions to help build Elements transactions to issue assets or transfer native currency (see [basic](src/sdk/basic)), as well as builder functions for the Options contract.
8-
9-
This SDK can be used as a reference for how to build libraries targeting a particular Simplicity contract, integrateable with mobile/desktop, etc.
7+
Wallet-facing transaction construction is schema-first and lives in the wallet ABI crate. Contract-side modules in this crate focus on program compilation, argument/witness helpers, execution, and transaction finalization primitives.
108

119
## License
1210

crates/contracts/src/error.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,6 @@ pub enum ValidationError {
2222
},
2323
}
2424

25-
/// Errors from taproot pubkey generation and verification.
26-
#[derive(Debug, thiserror::Error)]
27-
pub enum TaprootPubkeyGenError {
28-
#[error("Invalid pubkey recovered: expected {expected}, got {actual}")]
29-
InvalidPubkey { expected: String, actual: String },
30-
31-
#[error("Invalid address recovered: expected {expected}, got {actual}")]
32-
InvalidAddress { expected: String, actual: String },
33-
34-
#[error(
35-
"Invalid taproot pubkey gen string: expected 3 parts separated by ':', got {parts_count}"
36-
)]
37-
InvalidFormat { parts_count: usize },
38-
39-
#[error("Failed to decode seed hex: {0}")]
40-
SeedHexDecode(#[from] hex::FromHexError),
41-
42-
#[error("Failed to parse public key: {0}")]
43-
PublicKeyParse(#[from] simplicityhl::simplicity::bitcoin::key::ParsePublicKeyError),
44-
45-
#[error("Failed to parse address: {0}")]
46-
AddressParse(#[from] simplicityhl::elements::address::AddressError),
47-
48-
#[error("Failed to create X-only public key from bytes: {0}")]
49-
XOnlyPublicKey(#[from] simplicityhl::simplicity::bitcoin::secp256k1::Error),
50-
51-
#[error("Failed to generate address: {0}")]
52-
AddressGeneration(#[from] simplicityhl_core::ProgramError),
53-
}
54-
5525
/// Errors from transaction building operations.
5626
#[derive(Debug, thiserror::Error)]
5727
pub enum TransactionBuildError {
@@ -120,12 +90,6 @@ pub enum TransactionBuildError {
12090

12191
#[error(transparent)]
12292
Validation(#[from] ValidationError),
123-
124-
#[error(transparent)]
125-
TaprootPubkeyGen(#[from] TaprootPubkeyGenError),
126-
127-
#[error(transparent)]
128-
IssuanceValidation(#[from] crate::sdk::IssuanceVerificationError),
12993
}
13094

13195
/// Errors from extracting arguments from Arguments struct.

crates/contracts/src/finance/dcd/build_arguments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl DCDArguments {
557557
}
558558
}
559559

560-
impl simplicityhl_core::Encodable for DCDArguments {}
560+
impl wallet_abi::Encodable for DCDArguments {}
561561

562562
fn u256_from_le_hex(hex_le: &str) -> U256 {
563563
let mut bytes = <[u8; 32]>::from_hex(hex_le).expect("expected 32 bytes hex");

0 commit comments

Comments
 (0)