transaction is sent to blockchain however bot doesn't buy the token
This commit is contained in:
@@ -64,11 +64,12 @@ async fn main() -> Result<()> {
|
|||||||
let (_plan, prepared) = prepare_and_build(txu, &adapters, &kp_pub)?;
|
let (_plan, prepared) = prepare_and_build(txu, &adapters, &kp_pub)?;
|
||||||
|
|
||||||
// 2) Blockhash fresco + slot
|
// 2) Blockhash fresco + slot
|
||||||
let (new_bh, ctx_slot) = rpc.get_latest_blockhash().await?;
|
let (latest_blockhash, ctx_slot) = rpc.get_latest_blockhash().await?;
|
||||||
|
println!("latest_blockhash: {latest_blockhash}"); //si borro esto parece q no refresba bien latest_blockhash
|
||||||
println!("Latest slot solana: {ctx_slot}");
|
println!("Latest slot solana: {ctx_slot}");
|
||||||
|
|
||||||
// 3) Actualiza blockhash del mensaje
|
// 3) Actualiza blockhash del mensaje
|
||||||
let vm = set_recent_blockhash(prepared.message, new_bh);
|
let vm = set_recent_blockhash(prepared.message, latest_blockhash);
|
||||||
|
|
||||||
// 4) Firma con tu keypair
|
// 4) Firma con tu keypair
|
||||||
let vtx = sign_versioned_tx(vm, &[&kp])?;
|
let vtx = sign_versioned_tx(vm, &[&kp])?;
|
||||||
@@ -81,7 +82,7 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
|
|
||||||
// 6) Enviar
|
// 6) Enviar
|
||||||
let sig = rpc.send_transaction(&vtx, Some(ctx_slot)).await?;
|
let sig = rpc.send_transaction(&vtx, None).await?;
|
||||||
println!("🚀 Enviada: {}", sig);
|
println!("🚀 Enviada: {}", sig);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
19
src/rpc.rs
19
src/rpc.rs
@@ -93,13 +93,11 @@ struct GetLatestBlockhashValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
struct SimSendConfig<'a> {
|
struct SimSendConfig<'a> {
|
||||||
encoding: &'a str, // "base64"
|
encoding: &'a str, // "base64"
|
||||||
#[serde(rename = "sigVerify")]
|
sig_verify: bool,
|
||||||
sig_verify: bool, // false
|
replace_recent_blockhash: bool, // false
|
||||||
#[serde(rename = "replaceRecentBlockhash")]
|
|
||||||
replace_recent_blockhash: bool, // true/false
|
|
||||||
#[serde(rename = "commitment")]
|
|
||||||
commitment: &'a str,
|
commitment: &'a str,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@@ -107,7 +105,7 @@ struct SimSendConfig<'a> {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
skip_preflight: Option<bool>,
|
skip_preflight: Option<bool>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none", rename = "minContextSlot")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
min_context_slot: Option<u64>,
|
min_context_slot: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +156,7 @@ impl Rpc for HttpRpc {
|
|||||||
replace_recent_blockhash: false, // usa el mismo blockhash que envías
|
replace_recent_blockhash: false, // usa el mismo blockhash que envías
|
||||||
commitment: &self.commitment,
|
commitment: &self.commitment,
|
||||||
preflight_commitment: Some(&self.commitment),
|
preflight_commitment: Some(&self.commitment),
|
||||||
skip_preflight: None,
|
skip_preflight: Some(true),
|
||||||
min_context_slot,
|
min_context_slot,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -169,6 +167,7 @@ impl Rpc for HttpRpc {
|
|||||||
params: Some(vec![serde_json::json!(tx_b64), serde_json::to_value(cfg)?]),
|
params: Some(vec![serde_json::json!(tx_b64), serde_json::to_value(cfg)?]),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let resp: RpcResponse<serde_json::Value> = self
|
let resp: RpcResponse<serde_json::Value> = self
|
||||||
.client
|
.client
|
||||||
.post(&self.url)
|
.post(&self.url)
|
||||||
@@ -193,9 +192,9 @@ impl Rpc for HttpRpc {
|
|||||||
sig_verify: false,
|
sig_verify: false,
|
||||||
replace_recent_blockhash: false,
|
replace_recent_blockhash: false,
|
||||||
commitment: &self.commitment,
|
commitment: &self.commitment,
|
||||||
preflight_commitment: Some(&self.commitment),
|
preflight_commitment: None,
|
||||||
skip_preflight: Some(false),
|
skip_preflight: Some(true),
|
||||||
min_context_slot, // 👈 importante
|
min_context_slot: None
|
||||||
};
|
};
|
||||||
|
|
||||||
let req = RpcRequest {
|
let req = RpcRequest {
|
||||||
|
|||||||
Reference in New Issue
Block a user