Skip to content
Open
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: 2 additions & 2 deletions balius/src/bin/cargo-balius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn build() {
cmd.arg("build");
cmd.arg("--target");
cmd.arg("wasm32-unknown-unknown");

cmd.arg("--release");
let status = cmd.status().unwrap();

if !status.success() {
Expand All @@ -66,7 +66,7 @@ fn build() {

let (target_dir, package_name) = get_project_info();
let wasm_file = target_dir.join(format!(
"wasm32-unknown-unknown/debug/{}.wasm",
"wasm32-unknown-unknown/release/{}.wasm",
package_name
));

Expand Down
Binary file modified baliusd/bin/faucet.wasm
Binary file not shown.
16 changes: 8 additions & 8 deletions baliusd/example-mainnet/baliusd.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ name = "faucet"
module = "../bin/faucet.wasm"
config = "faucet.json"

[[workers]]
name = "wallet"
module = "../bin/wallet.wasm"
config = "wallet.json"
# [[workers]]
# name = "wallet"
# module = "../bin/wallet.wasm"
# config = "wallet.json"


[[workers]]
name = "asteria"
module = "../bin/asteria.wasm"
config = "asteria.json"
# [[workers]]
# name = "asteria"
# module = "../bin/asteria.wasm"
# config = "asteria.json"
11 changes: 11 additions & 0 deletions examples/minter/offchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@ edition = "2021"

[dependencies]
balius-sdk = { path = "../../../balius-sdk" }
hex = "0.4.3"
serde = { version = "1.0.204", features = ["derive"] }
serde_with = "3.9.0"
tx3-lang = { version = "0.1.0", path = "../../../../tx3/crates/tx3-lang" }
pallas-addresses = "0.31.0"

[lib]
crate-type = ["cdylib"]

[profile.release]
lto = true
opt-level = 's'

[dev-dependencies]
hex = "0.4.3"
serde_json = "1.0.128"
pallas-traverse = "0.31.0"
pallas-codec = "0.31.0"
pallas-primitives = "0.31.0"
tx3-vm = { version = "0.1.0", path = "../../../../tx3/crates/tx3-vm" }

[build-dependencies]
tx3-build = { version = "0.1.0", path = "../../../../tx3/crates/tx3-build" }

[package.metadata.release]
release = false
3 changes: 3 additions & 0 deletions examples/minter/offchain/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tx3_build::compile_tx3("faucet.tx3");
}
26 changes: 26 additions & 0 deletions examples/minter/offchain/faucet.tx3
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
policy PasswordPolicy = 0xef7a1cebb2dc7de884ddf82f8fcbc91fe9750dcd8c12ec7643a99bbe;

asset MyToken = 0xef7a1cebb2dc7de884ddf82f8fcbc91fe9750dcd8c12ec7643a99bbe.MYTOKEN;

party Requester;

tx claim_with_password(
password: Bytes,
quantity: Int
) {
input provided_gas {
from: Requester,
min_amount: fees,
}

mint {
amount: MyToken(quantity),
redeemer: password,
}

output {
to: Requester,
amount: provided_gas - fees + MyToken(quantity),
}
}

111 changes: 16 additions & 95 deletions examples/minter/offchain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,113 +1,34 @@
use balius_sdk::{
txbuilder::{
Address, AssetName, FeeChangeReturn, MinUtxoLovelace, MintBuilder, OutputBuilder,
ReferenceScript, TxBuilder, UtxoSource,
},
NewTx, WorkerResult,
};
use balius_sdk::{Config, FnHandler, Params, Worker};
use balius_sdk::{Config, FnHandler, Params, Worker, WorkerResult};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
use serde_with::serde_as;

#[derive(Serialize, Deserialize, Clone)]
struct FaucetConfig {
validator: ReferenceScript,
}
struct FaucetConfig {}

#[serde_as]
#[derive(Serialize, Deserialize)]
struct ClaimRequest {
token: AssetName,
quantity: u64,
#[serde_as(as = "DisplayFromStr")]
recipient: Address,
fuel: UtxoSource,
password: String,
requester: String,
}

balius_sdk::define_asset_class!(FaucetAsset, b"abcabcababcabcababcabcababca");

fn claim(config: Config<FaucetConfig>, params: Params<ClaimRequest>) -> WorkerResult<NewTx> {
let new_asset = FaucetAsset::value(params.token.clone(), params.quantity);
tx3_lang::include_tx3_build!("faucet");

let tx = TxBuilder::new()
.with_reference_input(config.validator.clone())
.with_input(params.fuel.clone())
.with_mint(
MintBuilder::new()
.with_asset(new_asset.clone())
.using_redeemer(()),
)
.with_output(
OutputBuilder::new()
.address(params.recipient.clone())
.with_value(MinUtxoLovelace)
.with_value(new_asset.clone()),
)
.with_output(FeeChangeReturn(params.fuel.clone()));
fn claim(
config: Config<FaucetConfig>,
params: Params<ClaimRequest>,
) -> WorkerResult<tx3_lang::ProtoTx> {
let tx_args = ClaimWithPasswordParams {
requester: params.requester.clone().into(),
password: hex::decode(&params.password).unwrap(),
quantity: params.quantity as i64,
};

Ok(NewTx(Box::new(tx)))
new_claim_with_password_tx(tx_args).map_err(|e| balius_sdk::Error::Internal(e.to_string()))
}

#[balius_sdk::main]
fn main() -> Worker {
Worker::new().with_request_handler("claim", FnHandler::from(claim))
}

#[cfg(test)]
mod tests {
use super::*;

use balius_sdk::txbuilder::{primitives, Address, Hash, UtxoSet};

use std::{collections::HashMap, str::FromStr as _};

#[test]
fn test_free_mint() {
let output = primitives::MintedTransactionOutput::PostAlonzo(primitives::MintedPostAlonzoTransactionOutput {
address: Address::from_bech32("addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x").unwrap().to_vec().into(),
value: primitives::Value::Coin(5_000_000),
datum_option: None,
script_ref: None,
});

let cbor = pallas_codec::minicbor::to_vec(&output).unwrap();

let test_utxos: HashMap<_, _> = vec![(
"f7d3837715680f3a170e99cd202b726842d97f82c05af8fcd18053c64e33ec4f#0"
.parse()
.unwrap(),
cbor,
)]
.into_iter()
.collect();

let _ledger = UtxoSet::from(test_utxos);

let config = FaucetConfig {
validator: ReferenceScript {
hash: Hash::from_str("ef7a1cebb2dc7de884ddf82f8fcbc91fe9750dcd8c12ec7643a99bbe").unwrap(),
address: Address::from_bech32("addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x").unwrap(),
ref_txo: primitives::TransactionInput {
transaction_id: Hash::from_str(
"f7d3837715680f3a170e99cd202b726842d97f82c05af8fcd18053c64e33ec4f",
)
.unwrap(),
index: 0,
},
},
};

let request = ClaimRequest {
token: AssetName::new(b"TEST".to_vec().into()).unwrap(),
quantity: 1,
recipient: Address::from_bech32("addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x").unwrap(),
fuel: UtxoSource::Refs(vec!["f7d3837715680f3a170e99cd202b726842d97f82c05af8fcd18053c64e33ec4f#0".parse().unwrap()]),
};

dbg!(serde_json::to_string(&request).unwrap());

let _tx = claim(Config(config), Params(request)).unwrap();

//let tx = balius_sdk::txbuilder::build(tx.0, ledger).unwrap();
}
}
4 changes: 3 additions & 1 deletion wit/balius.wit
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ interface ledger {

interface submit {
type cbor = list<u8>;
type tir = list<u8>;
type submit-error = u32;

resolve-tx: func(prototx: tir) -> result<cbor, submit-error>;
submit-tx: func(tx: cbor) -> result<_, submit-error>;
}

Expand Down Expand Up @@ -132,7 +134,7 @@ interface driver {
acknowledge,
json(json),
cbor(cbor),
partial-tx(cbor)
tx(cbor),
}

register-channel: func(id: u32, pattern: event-pattern);
Expand Down