Skip to content

Commit

Permalink
Add a few of the commands
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-mysten committed Oct 12, 2024
1 parent 12cac35 commit d3051bb
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 87 deletions.
2 changes: 2 additions & 0 deletions crates/sui-transaction-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ anyhow = "1.0"
bcs = "0.1.6"

[dev-dependencies]
base64ct = "1.6"
sui-crypto = { package = "sui-crypto", path = "../sui-crypto" , features = ["ed25519"] }
sui-graphql-client = { package = "sui-graphql-client", path = "../sui-graphql-client" }
tokio = { version = "1.0", features = ["full"] }
anyhow = "1.0"
Expand Down
58 changes: 48 additions & 10 deletions crates/sui-transaction-builder/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,71 @@
use anyhow::anyhow;
use base64ct::Encoding;
use std::str::FromStr;
use sui_crypto::ed25519::Ed25519PrivateKey;
use sui_crypto::SuiSigner;
use sui_graphql_client::Client;
use sui_transaction_builder::Object;
use sui_transaction_builder::Serialized;
use sui_transaction_builder::Transaction;
use sui_transaction_builder::TransactionBuilder;
use sui_types::types::Address;
use sui_types::types::ObjectDigest;
use sui_types::types::ObjectId;
use sui_types::types::UserSignature;

async fn example_without_literal_inference() -> Result<(), anyhow::Error> {
let client = Client::new_testnet();
// let wallet = /* ... */; // TBD how one gains access to a wallet.
let client = Client::new_localhost();

let mut tx = Transaction::new();
let mut tx = TransactionBuilder::new();
let coin_obj_id = "0x530b2f240cfa1e31d41cb1a4ce57b73084c767546feb1d8823809180114ed8b9";
let coin_digest = "6Tg9GrJnKSg6XXQv7eE2usMaN7EaaxbVvv34w5J4oBKo";
let coin_version = 2;

let coin = tx.input(Object::by_id(
ObjectId::from_str("0x8e78225d72b1d7b1f63e5e9f88f09b12ca66c84e2fc8b91fc10f6a0c51230615")
.map_err(|_| anyhow!("Invalid object ID"))?,
let coin = tx.input(Object::owned(
ObjectId::from_str(coin_obj_id).unwrap(),
coin_version,
ObjectDigest::from_str(coin_digest).map_err(|_| anyhow!("Invalid object digest"))?,
));

let recipient = tx.input(Serialized(
&Address::from_str("0xb67959920a1ea3e54ec15a1423fa0f3e5019c3b8e254df8b2a27dfab49049917")
&Address::from_str("0xeeaeb20e7b3a9cfce768a2ddf69503d8ae8d1628a26c2d74a435501c929d3f69")
.map_err(|_| anyhow!("Invalid address"))?,
));

println!("{:?}", tx);
tx.transfer_objects(vec![coin], recipient);
tx.set_gas_budget(500000000);
tx.set_gas_price(1000);
tx.set_gas(vec![Object::owned(
ObjectId::from_str("0x2e3a2b36a01cd6ad6b39788fc2bcbe9944ac482bccba1e9c6adea29a3c406f76")
.unwrap(),
2,
ObjectDigest::from_str("6A1VyFnpKKG28oaM9G4gwkkfh8DSAByxSBTQJvoyTMhd")
.map_err(|_| anyhow!("Invalid object digest"))?,
)]);
tx.set_sender(
Address::from_str("0x462ee1c227fc6365f842e2f4c9b7f66bbead607b128b68a7f7695cf2224c5168")
.unwrap(),
);

let tx = tx.finish()?;

let dry_run = client.dry_run_tx(&tx, None).await?;
println!("{:?}", dry_run);

let pk = base64ct::Base64::decode_vec("ALq6tKX5UqW5AyEqMj5Xq/zOC5tlKl/plh0afwooHZAn").unwrap();
let pk = Ed25519PrivateKey::new(pk[1..].try_into().expect("slice has wrong length"));

// let t = pk.sign_transaction(&tx);
// println!("{:?}", t);
//
// // println!("{:?}", t);
// let sig = "AGPG9CToY0r+3Uss5r2CVeHjD9rTZIvOhWLCqKe0Nj4JAfLZCnmJCGFgj+kC2/JHW4jRIsTfVUICbvRXyE3YtQGb4j7voyHkHCbVWoY0M/QxU8+gFDigeOxJIVqeaxKMSQ==";
// let sig = UserSignature::from_base64(&sig).unwrap();
//
// let effects = client.execute_tx(vec![sig], &tx).await?;
// println!("{:?}", effects);
// let split = tx.split_coins(
// coin,
// vec![tx.input(Serialized(&500u64)), tx.input(Serialized(&500u64))],
// vec![tx.input(Serialized(&500u64)), tx.input(Serialized(&500u64))],
// );
//
// let merge = tx.merge_coins(split.nested(0), vec![split.nested(1)]);
Expand Down
Loading

0 comments on commit d3051bb

Please sign in to comment.