Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental Ordinals Support #267

Merged
merged 5 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ package = "sapio-bitcoin"
version = "0.28.0"
features = ['use-serde', 'rand', 'base64']

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'rand', 'use-schemars', 'serde']

[dependencies.sapio]
path = "../sapio"
Expand Down
6 changes: 5 additions & 1 deletion cli/src/contracts/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
};
use sapio_wasm_plugin::{
host::{plugin_handle::ModuleLocator, PluginHandle, WasmPluginHandle},
CreateArgs, API,
CreateArgs, API, OrdinalsInfo,
};
use schemars::JsonSchema;
use serde::*;
use serde_json::Value;
use std::fmt::{Display, Formatter, Write};

Check warning on line 31 in cli/src/contracts/request.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `Write`

warning: unused import: `Write` --> cli/src/contracts/request.rs:31:36 | 31 | use std::fmt::{Display, Formatter, Write}; | ^^^^^ | = note: `#[warn(unused_imports)]` on by default
use std::{
collections::{BTreeMap, HashMap},
convert::TryInto,
Expand Down Expand Up @@ -73,6 +73,8 @@
pub outpoint: Option<OutPoint>,
pub use_txn: Option<String>,
pub compiled: Compiled,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub ordinals_info: Option<OrdinalsInfo>
}
pub type BindReturn = Program;
#[derive(Serialize, Deserialize, JsonSchema)]
Expand Down Expand Up @@ -271,6 +273,7 @@
use_txn,
compiled,
outpoint,
ordinals_info
} = self;
let use_txn = use_txn
.map(|buf| base64::decode(buf.as_bytes()))
Expand All @@ -285,6 +288,7 @@
emulator.clone(),
"mock".try_into()?,
Arc::new(MapEffectDB::default()),
ordinals_info
);
let mut tx = ctx
.template()
Expand Down Expand Up @@ -335,7 +339,7 @@
let logger = Rc::new(TxIndexLogger::new());
(*logger).add_tx(Arc::new(tx.clone()))?;
let mut bound = compiled.bind_psbt(
OutPoint::new(tx.txid(), vout as u32),

Check warning on line 342 in cli/src/contracts/request.rs

View workflow job for this annotation

GitHub Actions / clippy

casting to the same type is unnecessary (`u32` -> `u32`)

warning: casting to the same type is unnecessary (`u32` -> `u32`) --> cli/src/contracts/request.rs:342:38 | 342 | OutPoint::new(tx.txid(), vout as u32), | ^^^^^^^^^^^ help: try: `vout` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast = note: `#[warn(clippy::unnecessary_cast)]` on by default
BTreeMap::new(),
logger,
emulator.as_ref(),
Expand Down
2 changes: 2 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
let bytes = xpriv.sign(psbt, hash_ty)?;

if let Some(file_out) = output {
std::fs::write(file_out, &base64::encode(bytes))?;

Check warning on line 267 in cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> cli/src/main.rs:267:46 | 267 | std::fs::write(file_out, &base64::encode(bytes))?; | ^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `base64::encode(bytes)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
} else {
println!("{}", base64::encode(bytes));
}
Expand Down Expand Up @@ -314,7 +314,7 @@
let psbt = decode_psbt_file(args, "psbt")?;
let psbt = emulator.sign(psbt)?;
let bytes = serialize(&psbt);
std::fs::write(args.value_of_os("out").unwrap(), &base64::encode(bytes))?;

Check warning on line 317 in cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> cli/src/main.rs:317:70 | 317 | std::fs::write(args.value_of_os("out").unwrap(), &base64::encode(bytes))?; | ^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `base64::encode(bytes)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
}
Some(("get_key", args)) => {
let psbt = decode_psbt_file(args, "psbt")?;
Expand Down Expand Up @@ -499,6 +499,7 @@
client_auth: bitcoincore_rpc_async::Auth,
) -> Result<Command, Box<dyn Error>> {
let use_mock = args.is_present("mock");
let ordinals_info = None;
let use_base64 = args.is_present("base64_psbt");
let outpoint: Option<bitcoin::OutPoint> = args
.value_of("outpoint")
Expand All @@ -520,5 +521,6 @@
outpoint,
use_txn,
compiled,
ordinals_info
}))
}
5 changes: 0 additions & 5 deletions ctv_emulators/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ package = "sapio-bitcoin"
version = "0.28.0-rc.3"
features = ['use-serde', 'rand']

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'rand', 'use-schemars', 'serde']

[dependencies.sapio-base]
path = "../sapio-base"
version = "0.2.0"
Expand Down
1 change: 1 addition & 0 deletions ctv_emulators/src/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use super::*;
use bitcoin::consensus::encode::{Decodable, Encodable};
use miniscript::serde;
use sapio_base::miniscript;
use serde::de::Visitor;
use serde::de::*;
use serde::*;
Expand All @@ -17,7 +18,7 @@
/// a PSBT Wrapper type. Note that Serialize/Deserialize are manually implemented
/// limited to 1MB in size.
#[derive(Clone)]
pub struct PSBT(pub PartiallySignedTransaction);

Check warning on line 21 in ctv_emulators/src/msgs.rs

View workflow job for this annotation

GitHub Actions / clippy

name `PSBT` contains a capitalized acronym

warning: name `PSBT` contains a capitalized acronym --> ctv_emulators/src/msgs.rs:21:12 | 21 | pub struct PSBT(pub PartiallySignedTransaction); | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Psbt` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms = note: `#[warn(clippy::upper_case_acronyms)]` on by default

/// Wrapper for message serialization
#[derive(Serialize, Deserialize)]
Expand All @@ -43,7 +44,7 @@
A: SeqAccess<'de>,
{
let length_error =
|| de::Error::invalid_length(self.0 as usize, &"Expected at least 4 bytes.");

Check warning on line 47 in ctv_emulators/src/msgs.rs

View workflow job for this annotation

GitHub Actions / clippy

casting to the same type is unnecessary (`usize` -> `usize`)

warning: casting to the same type is unnecessary (`usize` -> `usize`) --> ctv_emulators/src/msgs.rs:47:42 | 47 | || de::Error::invalid_length(self.0 as usize, &"Expected at least 4 bytes."); | ^^^^^^^^^^^^^^^ help: try: `self.0` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast = note: `#[warn(clippy::unnecessary_cast)]` on by default
let len: usize = u32::from_be_bytes([
seq.next_element()?.ok_or_else(length_error)?,
seq.next_element()?.ok_or_else(length_error)?,
Expand Down
4 changes: 0 additions & 4 deletions emulator-trait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ package = "sapio-bitcoin"
version = "0.28.0"
features = ['use-serde']

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']

[dependencies.sapio-base]
path = "../sapio-base"
Expand Down
6 changes: 0 additions & 6 deletions examples/dcf_mining_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,3 @@ version = "0.2.0"
[dependencies.sapio-ctv-emulator-trait]
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'rand', 'use-schemars', 'serde']
optional = true
3 changes: 1 addition & 2 deletions examples/dcf_mining_pool/src/miner_payout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ impl MiningPayout {
for pay in v.iter() {
builder = builder.add_output(pay.0, pay.1.as_compilable(), None)?;
}
builder = builder.add_fees(self.fee_sats_per_tx)?;
return builder.into();
return builder.add_fees(self.fee_sats_per_tx)?.into();
} else {
let pay = Box::new(PayoutBundle {
contracts: v,
Expand Down
4 changes: 3 additions & 1 deletion plugin-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ members = ["treepay"
, "nft-sale"
, "nft-auction"
, "clause-module"
, "clause-module-trampoline"]
, "clause-module-trampoline"
, "ordinal-example"
, "ordinal-inscription"]
5 changes: 0 additions & 5 deletions plugin-example/batching-trait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ version = "0.2.0"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true


[dependencies.sapio-wasm-plugin]
Expand Down
5 changes: 0 additions & 5 deletions plugin-example/clause-module-trampoline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ path = "src/plugin.rs"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = false
Expand Down
3 changes: 2 additions & 1 deletion plugin-example/clause-module-trampoline/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ impl Callable for Wrapper {
amount: ctx.funds(),
network: ctx.network,
effects: unsafe { ctx.get_effects_internal() }.as_ref().clone(),
ordinals_info: ctx.get_ordinals().clone()
},
arguments: self.g.clone(),
};
self.v.call(ctx.path(), &create_args)
self.v.clone().call(ctx.path(), &create_args)
}
}

Expand Down
5 changes: 0 additions & 5 deletions plugin-example/clause-module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ path = "src/plugin.rs"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = false
Expand Down
5 changes: 0 additions & 5 deletions plugin-example/coin_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ path = "src/plugin.rs"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = false
Expand Down
6 changes: 0 additions & 6 deletions plugin-example/fedpeg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ path = "src/plugin.rs"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = false

Expand Down
6 changes: 0 additions & 6 deletions plugin-example/hanukkiah/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ path = "src/plugin.rs"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = false

Expand Down
6 changes: 0 additions & 6 deletions plugin-example/helloworld/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ path = "src/plugin.rs"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = false

Expand Down
7 changes: 0 additions & 7 deletions plugin-example/jamesob-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ path = "src/plugin.rs"
path = "../../emulator-trait"
version = "0.2.0"


[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = false

Expand Down
6 changes: 0 additions & 6 deletions plugin-example/nft-auction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ version = "0.2.0"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = false

Expand Down
4 changes: 2 additions & 2 deletions plugin-example/nft-auction/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use schemars::*;
use serde::*;
use std::convert::TryFrom;


use std::sync::Arc;

/// # Dutch Auction Data
Expand Down Expand Up @@ -145,7 +144,7 @@ impl NFTDutchAuction {
let amt = ctx.funds();
// first, let's get the module that should be used to 're-mint' this NFT
// to the new owner
let minting_module = self
let mut minting_module = self
.main
.data
.minting_module
Expand All @@ -162,6 +161,7 @@ impl NFTDutchAuction {
amount: ctx.funds(),
network: ctx.network,
effects: unsafe { ctx.get_effects_internal() }.as_ref().clone(),
ordinals_info: ctx.get_ordinals().clone(),
},
arguments: mint_impl::Versions::Mint_NFT_Trait_Version_0_1_0(mint_data),
};
Expand Down
6 changes: 0 additions & 6 deletions plugin-example/nft-sale/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ version = "0.2.0"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true


[dependencies.sapio-wasm-plugin]
path = "../../plugins"
Expand Down
5 changes: 3 additions & 2 deletions plugin-example/nft-sale/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ impl SimpleNFTSale {
let amt = ctx.funds();
// first, let's get the module that should be used to 're-mint' this NFT
// to the new owner
let minting_module =
let mut minting_module =
self.0.data.minting_module.as_ref().ok_or_else(|| {
CompilationError::TerminateWith("Must Provide Module Hash".into())
})?;
})?.clone();
// let's make a copy of the old nft metadata..
let mut mint_data = self.0.data.clone();
// and change the owner to the buyer
Expand All @@ -68,6 +68,7 @@ impl SimpleNFTSale {
amount: ctx.funds(),
network: ctx.network,
effects: unsafe { ctx.get_effects_internal() }.as_ref().clone(),
ordinals_info: ctx.get_ordinals().clone(),
},
arguments: mint_impl::Versions::Mint_NFT_Trait_Version_0_1_0(mint_data),
};
Expand Down
8 changes: 1 addition & 7 deletions plugin-example/nft-trait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ serde_derive = "1.0"

[dependencies.simp-pack]
path = "../../simp-pack"
version = "0.1.0"
version = "0.2.4"
[dependencies.schemars]
version = "0.8.0"
features = ['impl_json_schema']
Expand Down Expand Up @@ -45,9 +45,3 @@ version = "0.2.0"
[dependencies.sapio-ctv-emulator-trait]
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true
6 changes: 0 additions & 6 deletions plugin-example/nft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ version = "0.2.0"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true


[dependencies.sapio-wasm-plugin]
path = "../../plugins"
Expand Down
3 changes: 2 additions & 1 deletion plugin-example/nft/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl SellableNFT for SimpleNFT {
fn sell(self, mut ctx: Context, sale: Sell) {
if let Sell::MakeSale {
sale_info_partial,
which_sale,
mut which_sale,
} = sale
{
let sale_info = sale_info_partial.fill(self.data.clone());
Expand All @@ -83,6 +83,7 @@ impl SellableNFT for SimpleNFT {
amount: ctx.funds(),
network: ctx.network,
effects: unsafe { ctx.get_effects_internal() }.as_ref().clone(),
ordinals_info: ctx.get_ordinals().clone(),
},
arguments: sale_impl::Versions::NFT_Sale_Trait_Version_0_1_0(sale_info.clone()),
};
Expand Down
6 changes: 0 additions & 6 deletions plugin-example/op_return_chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ path = "src/plugin.rs"
path = "../../emulator-trait"
version = "0.2.0"

[dependencies.miniscript]
package = "sapio-miniscript"
version = "^7.0.0"
features = ['compiler', 'use-serde', 'use-schemars', 'serde']
optional = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = false

Expand Down
Loading
Loading