Skip to content

Commit

Permalink
wasm add memo
Browse files Browse the repository at this point in the history
  • Loading branch information
shaorongqiang committed Dec 22, 2023
1 parent b39321c commit 35f6cf5
Show file tree
Hide file tree
Showing 13 changed files with 952 additions and 117 deletions.
3 changes: 2 additions & 1 deletion src/components/finutils/src/bins/fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ fn run() -> Result<()> {
common::transfer_asset(
f.as_deref(),
t,
None,
token_code,
am.unwrap(),
m.is_present("confidential-amount"),
Expand Down Expand Up @@ -381,7 +382,7 @@ fn run() -> Result<()> {
} else {
common::transfer_asset_batch(
f.as_deref(),
&t,
&t.iter().map(|v| (v.clone(), None)).collect::<Vec<_>>(),
None,
am.unwrap(),
m.is_present("confidential-amount"),
Expand Down
12 changes: 9 additions & 3 deletions src/components/finutils/src/bins/stt/init/i_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ pub fn run_all() -> Result<()> {
.map(|v| &v.keypair)
.filter(|kp| kp.get_pk() != v0_kp.get_pk())
.collect::<Vec<_>>();
let targets = target_kps.iter().map(|kp| kp.get_pk()).collect::<Vec<_>>();
let targets = target_kps
.iter()
.map(|kp| (kp.get_pk(), None))
.collect::<Vec<_>>();
transfer_asset_batch_x(v0_kp, &targets, Some(code), 1, true, true).c(d!())?;
sleep_n_block!(1.2);
transfer_asset_batch_x(v0_kp, &targets, Some(code), 1, false, true).c(d!())?;
Expand Down Expand Up @@ -257,7 +260,7 @@ pub fn run_all() -> Result<()> {
balances += n;
transfer_asset_batch_x(
&v.keypair,
&[v_set[0].pubkey],
&[(v_set[0].pubkey, None)],
None,
n,
false,
Expand All @@ -283,7 +286,10 @@ pub fn run_all() -> Result<()> {
// 17.
println!(">>> Transfer to 10 random addresses ...");
let rkps = (0..10).map(|_| gen_random_keypair()).collect::<Vec<_>>();
let targets = rkps.iter().map(|kp| kp.get_pk()).collect::<Vec<_>>();
let targets = rkps
.iter()
.map(|kp| (kp.get_pk(), None))
.collect::<Vec<_>>();
transfer_asset_batch_x(
&v_set[0].keypair,
&targets,
Expand Down
16 changes: 10 additions & 6 deletions src/components/finutils/src/bins/stt/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn init(mut interval: u64, is_mainnet: bool, skip_validator: bool) -> Result
println!(">>> Block interval: {interval} seconds");

println!(">>> Define and issue FRA ...");
common::utils::send_tx(&fra_gen_initial_tx(&root_kp)).c(d!())?;
common::utils::send_tx(&fra_gen_initial_tx(&root_kp).into()).c(d!())?;

println!(">>> Wait 1.2 block ...");
sleep_n_block!(1.2, interval);
Expand All @@ -44,7 +44,7 @@ pub fn init(mut interval: u64, is_mainnet: bool, skip_validator: bool) -> Result
.values()
.map(|u| &u.pubkey)
.chain(VALIDATOR_LIST.values().map(|v| &v.pubkey))
.map(|pk| (pk, FRA_PRE_ISSUE_AMOUNT / 2_000))
.map(|pk| (pk, FRA_PRE_ISSUE_AMOUNT / 2_000, None))
.collect::<Vec<_>>();

// Wallet Address: fra18xkez3fum44jq0zhvwq380rfme7u624cccn3z56fjeex6uuhpq6qv9e4g5
Expand All @@ -56,7 +56,7 @@ pub fn init(mut interval: u64, is_mainnet: bool, skip_validator: bool) -> Result
let bank = pnk!(wallet::public_key_from_base64(
"Oa2RRTzdayA8V2OBE7xp3n3NKrjGJxFTSZZybXOXCDQ="
));
target_list.push((&bank, FRA_PRE_ISSUE_AMOUNT / 100 * 98));
target_list.push((&bank, FRA_PRE_ISSUE_AMOUNT / 100 * 98, None));

println!(">>> Transfer FRAs to validators ...");
common::utils::transfer_batch(&root_kp, target_list, None, true, true)
Expand All @@ -73,7 +73,7 @@ pub fn init(mut interval: u64, is_mainnet: bool, skip_validator: bool) -> Result
for (i, v) in VALIDATOR_LIST.values().enumerate() {
delegate::gen_tx(&v.name, (400_0000 + i as u64 * 1_0000) * FRA, &v.name)
.c(d!())
.and_then(|tx| common::utils::send_tx(&tx).c(d!()))?;
.and_then(|tx| common::utils::send_tx(&tx.into()).c(d!()))?;
}

println!(">>> Wait 5 block ...");
Expand Down Expand Up @@ -102,7 +102,7 @@ fn re_distribution() -> Result<()> {
if TX_FEE_MIN < n {
transfer_asset_batch_x(
&v.keypair,
&[v_set[0].pubkey],
&[(v_set[0].pubkey, None)],
None,
n - TX_FEE_MIN,
true,
Expand All @@ -128,7 +128,11 @@ fn re_distribution() -> Result<()> {
let expected = (400_0000 + 1_0000 * (v_set.len() as u64 - 1) + 1) * FRA;
transfer_asset_batch_x(
&v_set[0].keypair,
&v_set.iter().skip(1).map(|v| v.pubkey).collect::<Vec<_>>(),
&v_set
.iter()
.skip(1)
.map(|v| (v.pubkey, None))
.collect::<Vec<_>>(),
None,
expected,
true,
Expand Down
32 changes: 18 additions & 14 deletions src/components/finutils/src/bins/stt/stt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn run() -> Result<()> {
let amount = amount.unwrap().parse::<u64>().c(d!())?;
delegate::gen_tx(user.unwrap(), amount, validator.unwrap())
.c(d!())
.and_then(|tx| common::utils::send_tx(&tx).c(d!()))?;
.and_then(|tx| common::utils::send_tx(&tx.into()).c(d!()))?;
}
} else if let Some(m) = matches.subcommand_matches("undelegate") {
let user = m.value_of("user");
Expand All @@ -143,7 +143,7 @@ fn run() -> Result<()> {
let amount = amount.and_then(|am| am.parse::<u64>().ok());
undelegate::gen_tx(user.unwrap(), amount, validator)
.c(d!())
.and_then(|tx| common::utils::send_tx(&tx).c(d!()))?;
.and_then(|tx| common::utils::send_tx(&tx.into()).c(d!()))?;
}
} else if let Some(m) = matches.subcommand_matches("claim") {
let user = m.value_of("user");
Expand All @@ -158,7 +158,7 @@ fn run() -> Result<()> {
};
claim::gen_tx(user.unwrap(), amount)
.c(d!())
.and_then(|tx| common::utils::send_tx(&tx).c(d!()))?;
.and_then(|tx| common::utils::send_tx(&tx.into()).c(d!()))?;
}
} else if let Some(m) = matches.subcommand_matches("transfer") {
let from = m.value_of("from-user");
Expand All @@ -173,8 +173,10 @@ fn run() -> Result<()> {
.c(d!())
.map(|kp| kp.get_pk())
.or_else(|e| wallet::public_key_from_base64(receiver).c(d!(e)))?;
common::utils::transfer(owner_kp, &target_pk, am, None, false, false)
.c(d!())?;
common::utils::transfer(
owner_kp, &target_pk, am, None, false, false, None,
)
.c(d!())?;
}
_ => {
println!("{}", m.usage());
Expand All @@ -199,12 +201,14 @@ fn run() -> Result<()> {
}

mod issue {

use {
super::*,
finutils::transaction::BuildOperation,
ledger::{
data_model::{
AssetTypeCode, IssueAsset, IssueAssetBody, IssuerKeyPair, Operation,
TxOutput, ASSET_TYPE_FRA,
AssetTypeCode, IssueAsset, IssueAssetBody, IssuerKeyPair, TxOutput,
ASSET_TYPE_FRA,
},
staking::FRA_PRE_ISSUE_AMOUNT,
},
Expand All @@ -220,7 +224,7 @@ mod issue {
pub fn issue() -> Result<()> {
gen_issue_tx()
.c(d!())
.and_then(|tx| common::utils::send_tx(&tx).c(d!()))
.and_then(|tx| common::utils::send_tx(&tx.into()).c(d!()))
}

fn gen_issue_tx() -> Result<Transaction> {
Expand Down Expand Up @@ -265,8 +269,8 @@ mod issue {
let asset_issuance_operation =
IssueAsset::new(aib, &IssuerKeyPair { keypair: &root_kp }).c(d!())?;

builder.add_operation(Operation::IssueAsset(asset_issuance_operation));
Ok(builder.take_transaction())
builder.add_operation(BuildOperation::IssueAsset(asset_issuance_operation));
Ok(builder.take_transaction().into())
}
}

Expand All @@ -291,7 +295,7 @@ mod delegate {

common::utils::gen_transfer_op(
owner_kp,
vec![(&BLACK_HOLE_PUBKEY_STAKING, amount)],
vec![(&BLACK_HOLE_PUBKEY_STAKING, amount, None)],
None,
false,
false,
Expand All @@ -305,7 +309,7 @@ mod delegate {

let mut tx = builder.take_transaction();
tx.sign(owner_kp);
Ok(tx)
Ok(tx.into())
}
}

Expand Down Expand Up @@ -341,7 +345,7 @@ mod undelegate {
}
})?;

Ok(builder.take_transaction())
Ok(builder.take_transaction().into())
}
}

Expand All @@ -358,7 +362,7 @@ mod claim {
builder.add_operation_claim(None, owner_kp, amount);
})?;

Ok(builder.take_transaction())
Ok(builder.take_transaction().into())
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/components/finutils/src/common/ddev/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub(super) fn init(env: &mut Env) -> Result<()> {
.custom_data
.initial_validators
.iter()
.map(|v| (v.xfr_keypair.get_pk_ref(), 500_0000 * FRA))
.map(|v| (v.xfr_keypair.get_pk_ref(), 500_0000 * FRA, None))
.collect::<Vec<_>>();

println!("[ {} ] >>> Transfer FRAs to validators ...", &env.name);
Expand All @@ -118,7 +118,7 @@ pub(super) fn init(env: &mut Env) -> Result<()> {
gen_transfer_op_xx(
Some(&gen_8668_endpoint(env)),
&v.xfr_keypair,
vec![(&BLACK_HOLE_PUBKEY_STAKING, am)],
vec![(&BLACK_HOLE_PUBKEY_STAKING, am, None)],
None,
true,
false,
Expand All @@ -136,7 +136,7 @@ pub(super) fn init(env: &mut Env) -> Result<()> {
})?;
let mut tx = builder.take_transaction();
tx.sign(&v.xfr_keypair);
send_tx(env, &tx).c(d!())?;
send_tx(env, &tx.into()).c(d!())?;
}

println!("[ {} ] >>> Init work done !", &env.name);
Expand All @@ -154,7 +154,7 @@ fn setup_initial_validators(env: &Env) -> Result<()> {
.collect::<Vec<_>>();
builder.add_operation_update_validator(&[], 1, vs).c(d!())?;

send_tx(env, &builder.take_transaction()).c(d!())
send_tx(env, &builder.take_transaction().into()).c(d!())
}

fn send_tx(env: &Env, tx: &Transaction) -> Result<()> {
Expand All @@ -174,7 +174,7 @@ fn send_tx(env: &Env, tx: &Transaction) -> Result<()> {
fn transfer_batch(
env: &Env,
owner_kp: &XfrKeyPair,
target_list: Vec<(&XfrPublicKey, u64)>,
target_list: Vec<(&XfrPublicKey, u64, Option<String>)>,
token_code: Option<AssetTypeCode>,
confidential_am: bool,
confidential_ty: bool,
Expand All @@ -196,7 +196,7 @@ fn transfer_batch(
let mut tx = builder.take_transaction();
tx.sign(owner_kp);

send_tx(env, &tx).c(d!())
send_tx(env, &tx.into()).c(d!())
}

fn new_tx_builder(env: &Env) -> Result<TransactionBuilder> {
Expand Down
2 changes: 1 addition & 1 deletion src/components/finutils/src/common/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn transfer_to_account(

let transfer_op = utils::gen_transfer_op(
&kp,
vec![(&BLACK_HOLE_PUBKEY_STAKING, amount)],
vec![(&BLACK_HOLE_PUBKEY_STAKING, amount, None)],
asset,
false,
false,
Expand Down
Loading

0 comments on commit 35f6cf5

Please sign in to comment.