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
6 changes: 3 additions & 3 deletions examples/ebpf-counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
sdk = { path = "../../../sdk" }
arch_program = { path = "../../../program" }
bip322 = { path = "../../../bip322" }
sdk = { path = "../../sdk" }
arch_program = { path = "../../program" }
bip322 = { path = "../../bip322" }

bitcoincore-rpc = "0.19.0"
hex = "0.4.3"
Expand Down
32 changes: 9 additions & 23 deletions examples/ebpf-counter/src/counter_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ pub fn try_deploy_program(
program_file_path: &str,
program_name: &str,
) -> anyhow::Result<arch_program::pubkey::Pubkey> {
use arch_program::pubkey::Pubkey;
use arch_program::{
account::AccountMeta, instruction::Instruction, system_instruction::SystemInstruction,
};
use arch_program::system_instruction::SystemInstruction;
use sdk::constants::*;
use sdk::helper::*;
use std::fs;
Expand All @@ -19,16 +16,13 @@ pub fn try_deploy_program(

let elf = fs::read(elf_path).expect("elf path should be available");

match read_account_info(NODE1_ADDRESS, program_pubkey) {
Ok(account_info_result) => {
if account_info_result.data != elf {
error!("Program account content is different from provided ELF file !");
panic!();
}
println!("\x1b[33m Same program already deployed ! Skipping deployment. \x1b[0m");
return Ok(program_pubkey);
if let Ok(account_info_result) = read_account_info(NODE1_ADDRESS, program_pubkey) {
if account_info_result.data != elf {
error!("Program account content is different from provided ELF file !");
panic!();
}
Err(_) => {}
println!("\x1b[33m Same program already deployed ! Skipping deployment. \x1b[0m");
return Ok(program_pubkey);
};

let (deploy_utxo_btc_txid, deploy_utxo_vout) = send_utxo(program_pubkey);
Expand Down Expand Up @@ -77,15 +71,7 @@ pub fn try_deploy_program(
println!("\x1b[32m Step 3/4 Successful :\x1b[0m Sent ELF file as transactions, and verified program account's content against local ELF file!");

let (executability_txid, _) = sign_and_send_instruction(
Instruction {
program_id: Pubkey::system_program(),
accounts: vec![AccountMeta {
pubkey: program_pubkey,
is_signer: true,
is_writable: true,
}],
data: vec![2],
},
SystemInstruction::new_deploy_instruction(program_pubkey),
vec![program_keypair],
)
.expect("signing and sending a transaction should not fail");
Expand All @@ -111,5 +97,5 @@ pub fn try_deploy_program(

println!("\x1b[1m\x1b[32m================================================================================== PROGRAM DEPLOYMENT : OK ! ==================================================================================\x1b[0m");

return Ok(program_pubkey);
Ok(program_pubkey)
}
24 changes: 9 additions & 15 deletions examples/ebpf-counter/src/counter_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{anyhow, Result};
use arch_program::account::AccountMeta;
use arch_program::instruction::Instruction;
use arch_program::pubkey::Pubkey;
use arch_program::system_instruction::SystemInstruction;
use arch_program::utxo::UtxoMeta;
use bitcoin::key::{Keypair, UntweakedKeypair};
use bitcoin::XOnlyPublicKey;
Expand Down Expand Up @@ -115,15 +114,10 @@ pub fn assign_ownership_to_program(
instruction_data.extend(program_pubkey.serialize());

let (txid, _) = sign_and_send_instruction(
Instruction {
program_id: Pubkey::system_program(),
accounts: vec![AccountMeta {
pubkey: account_to_transfer_pubkey,
is_signer: true,
is_writable: true,
}],
data: instruction_data,
},
SystemInstruction::new_assign_ownership_instruction(
account_to_transfer_pubkey,
*program_pubkey,
),
vec![current_owner_keypair],
)
.expect("signing and sending a transaction should not fail");
Expand All @@ -149,7 +143,7 @@ pub fn generate_new_keypair() -> (UntweakedKeypair, Pubkey, Address) {
}

pub(crate) fn get_account_counter(account_pubkey: &Pubkey) -> Result<CounterData> {
let account_info = read_account_info(NODE1_ADDRESS, account_pubkey.clone())
let account_info = read_account_info(NODE1_ADDRESS, *account_pubkey)
.map_err(|e| anyhow!(format!("Error reading account content {}", e.to_string())))?;

let mut account_info_data = account_info.data.as_slice();
Expand All @@ -161,15 +155,15 @@ pub(crate) fn get_account_counter(account_pubkey: &Pubkey) -> Result<CounterData
}

pub(crate) fn generate_anchoring(account_pubkey: &Pubkey) -> (UtxoMeta, Vec<u8>) {
let (utxo_txid, utxo_vout) = send_utxo(account_pubkey.clone());
let (utxo_txid, utxo_vout) = send_utxo(*account_pubkey);

let fees_psbt = prepare_fees();

return (
(
UtxoMeta::from(
hex::decode(utxo_txid.clone()).unwrap().try_into().unwrap(),
utxo_vout,
),
hex::decode(fees_psbt).unwrap(),
);
)
}
16 changes: 7 additions & 9 deletions examples/ebpf-counter/src/counter_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) fn start_new_counter(

let (txid, _) = sign_and_send_instruction(
arch_program::instruction::Instruction {
program_id: program_pubkey.clone(),
program_id: *program_pubkey,
accounts: vec![AccountMeta {
pubkey: account_pubkey,
is_signer: true,
Expand Down Expand Up @@ -145,9 +145,9 @@ pub(crate) fn get_counter_increase_instruction(
.unwrap();

Instruction {
program_id: program_pubkey.clone(),
program_id: *program_pubkey,
accounts: vec![AccountMeta {
pubkey: account_pubkey.clone(),
pubkey: *account_pubkey,
is_signer: true,
is_writable: true,
}],
Expand Down Expand Up @@ -184,13 +184,11 @@ pub fn build_transaction(
})
.collect::<Vec<Signature>>();

let params = RuntimeTransaction {
RuntimeTransaction {
version: 0,
signatures,
message,
};

params
}
}

pub fn build_and_send_block(transactions: Vec<RuntimeTransaction>) -> Vec<String> {
Expand All @@ -201,7 +199,7 @@ pub fn build_and_send_block(transactions: Vec<RuntimeTransaction>) -> Vec<String
let transaction_ids: Vec<String> =
bitcoincore_rpc::jsonrpc::serde_json::from_value(result).expect("Couldn't decode response");

return transaction_ids;
transaction_ids
}

pub fn fetch_processed_transactions(
Expand Down Expand Up @@ -263,5 +261,5 @@ pub fn fetch_processed_transactions(
}
pb.finish();

return Ok(processed_transactions);
Ok(processed_transactions)
}
2 changes: 2 additions & 0 deletions examples/ebpf-counter/src/errors_and_panics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ fn counter_init_and_two_inc_second_anchored_fail() {

log_scenario_end(20, &format!("{:?}", final_account_data));
}

#[ignore]
#[serial]
#[test]
Expand Down Expand Up @@ -894,6 +895,7 @@ fn counter_init_and_two_inc_tx_anchored_fail_2nd_succeed() {
),
);
}

#[ignore]
#[serial]
#[test]
Expand Down
23 changes: 12 additions & 11 deletions examples/ebpf-counter/src/happy_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ use crate::{
},
ELF_PATH,
};

#[ignore]
#[serial]
#[test]
fn counter_initialization_test() {
init_logging();

log_scenario_start(1,
&"Program Deployment & Counter Initialization".to_string(),
&"Happy Path Scenario : deploying the counter program, then initializing the counter to (1,1) ".to_string()
"Program Deployment & Counter Initialization",
"Happy Path Scenario : deploying the counter program, then initializing the counter to (1,1) "
);

let program_pubkey = try_deploy_program(ELF_PATH, PROGRAM_FILE_PATH, "E2E-Counter").unwrap();

start_new_counter(&program_pubkey, 1, 1).unwrap();

log_scenario_end(1, &format!(""));
log_scenario_end(1, "");
}

#[ignore]
Expand All @@ -37,8 +38,8 @@ fn counter_init_and_inc_test() {
init_logging();

log_scenario_start(2,
&"Counter Initialization and Increase ( Two overlapping states, in two separate blocks )".to_string(),
&"Happy Path Scenario : Initializing the counter to (1,1), then increasing it in a separate block ".to_string()
"Counter Initialization and Increase ( Two overlapping states, in two separate blocks )",
"Happy Path Scenario : Initializing the counter to (1,1), then increasing it in a separate block "
);

let program_pubkey = try_deploy_program(ELF_PATH, PROGRAM_FILE_PATH, "E2E-Counter").unwrap();
Expand Down Expand Up @@ -68,8 +69,8 @@ fn counter_init_and_inc_transaction_test() {
init_logging();

log_scenario_start(3,
&"Counter Initialization and Increase ( Two overlapping states, in the same transaction )".to_string(),
&"Happy Path Scenario : Initializing the counter to (1,1), then increasing it twice in the same transaction, using two separate instructions".to_string()
"Counter Initialization and Increase ( Two overlapping states, in the same transaction )",
"Happy Path Scenario : Initializing the counter to (1,1), then increasing it twice in the same transaction, using two separate instructions"
);

let program_pubkey = try_deploy_program(ELF_PATH, PROGRAM_FILE_PATH, "E2E-Counter").unwrap();
Expand Down Expand Up @@ -105,8 +106,8 @@ fn counter_init_and_inc_block_test() {
init_logging();

log_scenario_start(4,
&"Counter Initialization and Increase ( Two overlapping states, in the same block )".to_string(),
&"Happy Path Scenario : Initializing the counter to (1,1), then increasing it twice in the same block, using two separate transactions".to_string()
"Counter Initialization and Increase ( Two overlapping states, in the same block )",
"Happy Path Scenario : Initializing the counter to (1,1), then increasing it twice in the same block, using two separate transactions"
);

let program_pubkey = try_deploy_program(ELF_PATH, PROGRAM_FILE_PATH, "E2E-Counter").unwrap();
Expand Down Expand Up @@ -147,8 +148,8 @@ fn counter_init_and_inc_anchored() {
init_logging();

log_scenario_start(15,
&"Counter Initialization and Increase ( 1 Anchored Instruction )".to_string(),
&"Happy Path Scenario : Initializing the counter to (1,1), then increasing it with a Bitcoin Transaction Anchoring".to_string()
"Counter Initialization and Increase ( 1 Anchored Instruction )",
"Happy Path Scenario : Initializing the counter to (1,1), then increasing it with a Bitcoin Transaction Anchoring"
);

let program_pubkey = try_deploy_program(ELF_PATH, PROGRAM_FILE_PATH, "E2E-Counter").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions examples/fungible-token-standard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
arch_program = { path = "../../../program" }
arch_program = { path = "../../program" }
ebpf-counter = { path = "../ebpf-counter" }
sdk = { path = "../../../sdk" }
sdk = { path = "../../sdk" }
fungible-token-standard-program = { path = "./program" , features = ["no-entrypoint"] }

bitcoincore-rpc = "0.18.0"
Expand Down
23 changes: 3 additions & 20 deletions examples/fungible-token-standard/program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
/* ---------- BUILD USING CARGO_TARGET_DIR=./target cargo build-sbf --------- */
use arch_program::{
account::AccountInfo,
entrypoint,
helper::add_state_transition,
input_to_sign::InputToSign,
msg,
program::{
get_account_script_pubkey, get_bitcoin_block_height, invoke, next_account_info,
set_transaction_to_sign,
},
program_error::ProgramError,
account::AccountInfo, entrypoint, msg, program::next_account_info, program_error::ProgramError,
pubkey::Pubkey,
system_instruction::SystemInstruction,
transaction_to_sign::TransactionToSign,
utxo::UtxoMeta,
};
use bitcoin::{self, absolute::LockTime, transaction::Version, Transaction};
use borsh::{BorshDeserialize, BorshSerialize};
use mint::{
initialize_mint, mint_tokens, InitializeMintInput, MintInput, MintStatus, TokenMintDetails,
};
use std::collections::HashMap;
use token_account::{initialize_balance_account, TokenBalance};
use mint::{initialize_mint, mint_tokens, InitializeMintInput, MintInput};
use token_account::initialize_balance_account;
use transfer::{transfer_tokens, TransferInput};
pub mod errors;
pub mod mint;
Expand Down
2 changes: 1 addition & 1 deletion examples/fungible-token-standard/program/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub(crate) fn initialize_mint(
let serialized_mint_details = borsh::to_vec(&mint_initial_details)
.map_err(|e| ProgramError::BorshIoError(e.to_string()))?;

if serialized_mint_details.len() > 0 {
if !serialized_mint_details.is_empty() {
account.realloc(serialized_mint_details.len(), true)?;
}

Expand Down
7 changes: 2 additions & 5 deletions examples/fungible-token-standard/program/src/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use arch_program::{account::AccountInfo, msg, program_error::ProgramError, pubkey::Pubkey};
use arch_program::{account::AccountInfo, program_error::ProgramError, pubkey::Pubkey};
use borsh::{BorshDeserialize, BorshSerialize};

use crate::{
mint::{MintStatus, TokenMintDetails},
token_account::TokenBalance,
};
use crate::{mint::TokenMintDetails, token_account::TokenBalance};

#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
pub struct TransferInput {
Expand Down
13 changes: 5 additions & 8 deletions examples/fungible-token-standard/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ use ebpf_counter::{
counter_helpers::{generate_new_keypair, init_logging},
counter_instructions::{build_and_send_block, build_transaction, fetch_processed_transactions},
};
use fungible_token_standard_program::{mint::InitializeMintInput, token_account::TokenBalance};
use fungible_token_standard_program::mint::InitializeMintInput;
use sdk::processed_transaction::Status;
use sdk::{
constants::{NODE1_ADDRESS, PROGRAM_FILE_PATH},
helper::{get_processed_transaction, read_account_info, send_utxo, sign_and_send_instruction},
};
use serial_test::serial;

use borsh::{BorshDeserialize, BorshSerialize};
use borsh::BorshSerialize;

use crate::{
helpers::{
create_balance_account, get_balance_account, get_mint_info,
provide_empty_account_to_program, try_create_mint_account,
},
instruction::{
assign_ownership_instruction, create_new_account_instruction, mint_request_instruction,
provide_empty_account_to_program,
},
standard_tests::ELF_PATH,
};
Expand Down Expand Up @@ -59,7 +56,7 @@ fn deploy_standard_program() {
.expect("Couldnt serialize mint input");

let initialize_mint_instruction = Instruction {
program_id: program_pubkey.clone(),
program_id: program_pubkey,
accounts: vec![AccountMeta {
pubkey: mint_account_pubkey,
is_signer: true,
Expand Down Expand Up @@ -109,7 +106,7 @@ fn deploy_standard_program() {

println!("User account {:?}", account_pubkey.serialize());

let account_info = read_account_info(NODE1_ADDRESS, account_pubkey.clone())
let account_info = read_account_info(NODE1_ADDRESS, account_pubkey)
.map_err(|e| anyhow!(format!("Error reading account content {}", e.to_string())))
.unwrap();

Expand Down
Loading