tonlib-rs
tonlib-rs copied to clipboard
Example does not compile
README create simple transfer example does not compile.
Code:
use num_bigint::BigUint;
use std::time::SystemTime;
use tonlib::address::TonAddress;
use tonlib::cell::BagOfCells;
use tonlib::message::TransferMessage;
use tonlib::wallet::TonWallet;
use tonlib::client::TonClient;
use tonlib::client::TonClientInterface;
use tonlib::mnemonic::Mnemonic;
use tonlib::wallet::WalletVersion;
async fn create_simple_transfer() -> anyhow::Result<()> {
let mnemonic = Mnemonic::new(
vec![
"dose", "ice", "enrich", "trigger", "test", "dove", "century", "still", "betray",
"gas", "diet", "dune",
],
&None,
)?;
let key_pair = mnemonic.to_key_pair()?;
let seqno = 30000000;
let client = TonClient::default().await?;
let wallet = TonWallet::derive_default(WalletVersion::V4R2, &key_pair)?;
let dest: TonAddress = "<destination wallet address>".parse()?;
let value = BigUint::from(10000000u64); // 0.01 TON
let transfer = TransferMessage::new(&dest, &value).build()?;
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)?
.as_secs() as u32;
let body = wallet.create_external_body(now + 60, seqno, vec![transfer])?;
let signed = wallet.sign_external_body(&body)?;
let wrapped = wallet.wrap_signed_body(signed, false)?;
let boc = BagOfCells::from_root(wrapped);
let tx = boc.serialize(true)?;
let hash = client.send_raw_message_return_hash(tx.as_slice()).await?;
Ok(())
}
fn main() {
create_simple_transfer();
}
Error:
error[E0277]: the trait bound `Vec<tonlib::cell::Cell>: AsRef<[Arc<tonlib::cell::Cell>]>` is not satisfied
--> src/main.rs:35:61
|
35 | let body = wallet.create_external_body(now + 60, seqno, vec![transfer])?;
| -------------------- ^^^^^^^^^^^^^^ the trait `AsRef<[Arc<tonlib::cell::Cell>]>` is not implemented for `Vec<tonlib::cell::Cell>`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `AsRef<T>`:
<Vec<T, A> as AsRef<Vec<T, A>>>
<Vec<T, A> as AsRef<[T]>>
note: required by a bound in `TonWallet::create_external_body`
--> /User/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tonlib-0.15.4/src/wallet.rs:246:36
|
246 | pub fn create_external_body<T: AsRef<[ArcCell]>>(
| ^^^^^^^^^^^^^^^^ required by this bound in `TonWallet::create_external_body`
Rust version:
rustc --version:
rustc 1.79.0 (129f3b996 2024-06-10)
Cargo.toml:
[dependencies]
anyhow = "1.0"
num-bigint = "0.4"
tonlib = "0.15"
tokio = { version = "1", features = ["full"] }