crates/coin: cleanup old unused code

This commit is contained in:
Ryan Heywood 2024-11-26 07:14:10 -05:00
parent 499edce086
commit 971c58ade3
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
8 changed files with 5 additions and 183 deletions

View File

@ -1,12 +1,10 @@
[workspace]
resolver = "2"
members = [ "crates/by-chain/icepick-solana",
"crates/coin/icepick-coin",
"crates/coin/icepick-eth",
"crates/coin/icepick-sol",
"crates/icepick", "crates/icepick-module",
"vendor/solana-sdk",
members = [
"crates/icepick",
"crates/icepick-module",
"crates/by-chain/icepick-solana",
]
[workspace.dependencies]

View File

@ -148,7 +148,7 @@ impl Module for Solana {
to_address,
from_address,
blockhash,
fee,
fee: _,
fee_payer,
fee_payer_address,
}) => {

View File

@ -1,8 +0,0 @@
[package]
name = "icepick-coin"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = "4.5.21"
thiserror = "2.0.3"

View File

@ -1,37 +0,0 @@
use clap::{Command, ArgMatches};
#[derive(thiserror::Error, Debug)]
#[error("The requested operation is unsupported or not yet implemented")]
pub struct Unsupported;
pub trait Coin {
/// Return the name for the coin, in lowercase.
fn coin_name(&self) -> &'static str;
/// Return a description of the coin.
fn coin_description(&self) -> &'static str;
/// Given a Command, add any arguments relevant to the Transfer operation.
///
/// All commands by default have the following values:
/// * `amount`: The amount of the currency to transfer. May be a float.
/// * `to`: The account to transfer the currency to.
/// * `from_account`: The non-default derivation account to send currency from.
fn build_transfer_command(&self, _command: Command) -> Result<Command, Unsupported> {
Err(Unsupported)
}
/// Given a Command, add any arguments relevant to the Stake operation.
fn build_stake_command(&self, _command: Command) -> Result<Command, Unsupported> {
Err(Unsupported)
}
/// Perform a Transfer
///
/// TODO: This should later be split into "make a transfer",
/// "verify a transfer", "sign a transfer", and "broadcast the transfer".
#[allow(unused_variables)]
fn run_transfer_command(&self, matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
Err(Box::new(Unsupported))
}
}

View File

@ -1,8 +0,0 @@
[package]
name = "icepick-eth"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = "4.5.21"
icepick-coin = { version = "0.1.0", path = "../icepick-coin" }

View File

@ -1,24 +0,0 @@
use clap::arg;
use icepick_coin::{Coin, Unsupported};
pub struct ETH;
impl Coin for ETH {
fn coin_name(&self) -> &'static str {
"eth"
}
fn coin_description(&self) -> &'static str {
"The leading platform for innovative apps and blockchain networks."
}
fn build_transfer_command(&self, command: clap::Command) -> Result<clap::Command, Unsupported> {
Ok(command
.arg(arg!(--gas <GAS> "Specify custom gas for the transaction."))
.arg(arg!(--"gas-payer" <ACCOUNT> "Use an alternative derivation account for paying gas.")))
}
fn build_stake_command(&self, _command: clap::Command) -> Result<clap::Command, Unsupported> {
Err(Unsupported)
}
}

View File

@ -1,9 +0,0 @@
[package]
name = "icepick-sol"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = "4.5.21"
icepick-coin = { version = "0.1.0", path = "../icepick-coin" }
solana-sdk = { version = "2.1.1", features = [], default-features = false }

View File

@ -1,90 +0,0 @@
use clap::{arg, ArgMatches, Command};
use icepick_coin::{Coin, Unsupported};
use solana_sdk::{instruction::Instruction, pubkey::Pubkey, system_instruction};
use std::str::FromStr;
pub struct SOL;
impl Coin for SOL {
fn coin_name(&self) -> &'static str {
"sol"
}
fn coin_description(&self) -> &'static str {
"Bring blockchain to the people. Solana supports experiences for power users, new consumers, and everyone in between."
}
fn build_transfer_command(&self, command: Command) -> Result<Command, Unsupported> {
Ok(command
.arg(arg!(--"fee-payer" [FEE_PAYER] "Use an alternative derivation account for paying fees."))
.arg(arg!(--"blockhash" <BLOCKHASH> "A recent blockhash to include in the Transaction")))
}
fn build_stake_command(&self, _command: Command) -> Result<Command, Unsupported> {
Err(Unsupported)
}
fn run_transfer_command(&self, matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
let amount = matches
.get_one::<String>("amount")
.and_then(|amount| u64::from_str(amount).ok())
.expect("amount: valid int");
let to_address = matches
.get_one::<String>("to-address")
.and_then(|pk| Pubkey::from_str(pk).ok())
.expect("to-address: valid public key");
let from_account = matches
.get_one::<String>("from-account")
.and_then(|index| u32::from_str(index).ok())
.filter(|index| *index < (1 << 31));
let fee_payer = matches.get_one::<String>("fee-payer");
let blockhash = matches.get_one::<String>("blockhash");
// We need: pubkey 1, pubkey 2, lamports,
let instruction = system_instruction::transfer(&to_address, &to_address, amount);
print_instruction(&instruction);
Ok(())
}
}
fn guess_instruction(i: &Instruction) -> Option<String> {
let data = &i.data;
let instruction = data[..4]
.try_into()
.ok()
.map(u32::from_le_bytes)?;
let system_program = solana_sdk::system_program::ID;
let entries = [(system_program, 2u32, |data: &[u8]| {
let lamports = data[..8]
.try_into()
.ok()
.map(u64::from_le_bytes)
.expect("unable to parse data into lamport amount");
format!("transfer {lamports} lamports")
})];
entries
.iter()
.find(|entry| entry.0 == i.program_id && entry.1 == instruction)
.map(|entry| entry.2(&data[4..]))
}
fn print_instruction(instruction: &Instruction) {
println!("Program ID: {}", instruction.program_id);
if !instruction.accounts.is_empty() {
println!("Associated Accounts:");
for account in &instruction.accounts {
println!("|- Public Key: {}", account.pubkey);
println!("|- Is Signer: {}", account.is_signer);
println!("\\- Is Writable: {}", account.is_writable);
}
match guess_instruction(instruction) {
Some(guess) => {
println!("Instruction: {guess}");
}
None => {
println!("Unknown instruction: {:?}", instruction.data);
}
}
}
}