Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor with framework sdk #4301

Closed
Closed
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
2 changes: 1 addition & 1 deletion cmd/airdrop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ async fn main() -> Result<()> {
let script_function = EntryFunction::new(
ModuleId::new(
genesis_address(),
Identifier::new("TransferScripts").unwrap(),
Identifier::new("transfer_scripts").unwrap(),
),
Identifier::new("batch_peer_to_peer_v2").unwrap(),
vec![token_type.clone().into()],
Expand Down
2 changes: 1 addition & 1 deletion cmd/db-exporter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ pub fn create_account_txn_sent_as_association(
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
starcoin_vm_types::account_config::core_code_address(),
Identifier::new("Account").unwrap(),
Identifier::new("account").unwrap(),
),
Identifier::new("create_account_with_initial_amount").unwrap(),
vec![stc_type_tag()],
Expand Down
2 changes: 1 addition & 1 deletion cmd/starcoin/src/account/accept_token_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl CommandAction for AcceptTokenCommand {
ctx.state().build_and_execute_transaction(
opt.transaction_opts.clone(),
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(core_code_address(), Identifier::new("Account").unwrap()),
ModuleId::new(core_code_address(), Identifier::new("account").unwrap()),
Identifier::new("accept_token").unwrap(),
vec![TypeTag::Struct(Box::new(
opt.token_code.clone().try_into().unwrap(),
Expand Down
9 changes: 3 additions & 6 deletions cmd/starcoin/src/account/transfer_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use starcoin_transaction_builder::encode_transfer_script_by_token_code;
use starcoin_types::account_address::AccountAddress;
use starcoin_vm_types::token::stc::G_STC_TOKEN_CODE;
use starcoin_vm_types::token::token_code::TokenCode;
use starcoin_vm_types::transaction::TransactionPayload;

use crate::cli_state::CliState;
use crate::view::{ExecuteResultView, TransactionOptions};
Expand Down Expand Up @@ -60,11 +59,9 @@ impl CommandAction for TransferCommand {
.token_code
.clone()
.unwrap_or_else(|| G_STC_TOKEN_CODE.clone());
let script_function =
let payload =
encode_transfer_script_by_token_code(receiver_address, opt.amount, token_code);
ctx.state().build_and_execute_transaction(
opt.transaction_opts.clone(),
TransactionPayload::EntryFunction(script_function),
)
ctx.state()
.build_and_execute_transaction(opt.transaction_opts.clone(), payload)
}
}
6 changes: 2 additions & 4 deletions cmd/starcoin/src/dev/gen_block_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::StarcoinOpt;
use anyhow::{ensure, Result};
use clap::Parser;
use scmd::{CommandAction, ExecContext};
use starcoin_transaction_builder::build_empty_script;
use starcoin_types::transaction::TransactionPayload;
use starcoin_transaction_builder::empty_txn_payload;

/// Trigger a new block in dev.
#[derive(Debug, Parser)]
Expand All @@ -30,13 +29,12 @@ impl CommandAction for GenBlockCommand {
let cli_state = ctx.state();
let net = cli_state.net();
ensure!(net.is_dev(), "Only dev network support this command");
let empty = build_empty_script();
let txn_opts = TransactionOptions {
blocking: true,
dry_run: false,
..Default::default()
};
ctx.state()
.build_and_execute_transaction(txn_opts, TransactionPayload::EntryFunction(empty))
.build_and_execute_transaction(txn_opts, empty_txn_payload())
}
}
5 changes: 2 additions & 3 deletions cmd/starcoin/src/dev/get_coin_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use starcoin_types::account_config;
use starcoin_types::account_config::STCUnit;
use starcoin_vm_types::account_config::G_STC_TOKEN_CODE;
use starcoin_vm_types::token::token_value::TokenValue;
use starcoin_vm_types::transaction::TransactionPayload;
use std::time::Duration;

/// Get stc to default account.
Expand Down Expand Up @@ -71,11 +70,11 @@ impl CommandAction for GetCoinCommand {
state
.build_and_execute_transaction(
txn_opt,
TransactionPayload::EntryFunction(encode_transfer_script_by_token_code(
encode_transfer_script_by_token_code(
to,
opt.amount.scaling(),
G_STC_TOKEN_CODE.clone(),
)),
),
)?
.get_transaction_info()
} else {
Expand Down
7 changes: 2 additions & 5 deletions cmd/starcoin/src/dev/upgrade_vm_config_proposal_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use starcoin_rpc_client::StateRootOption;
use starcoin_transaction_builder::build_vm_config_upgrade_proposal;
use starcoin_vm_runtime::starcoin_vm::StarcoinVM;
use starcoin_vm_types::on_chain_config::VMConfig;
use starcoin_vm_types::transaction::TransactionPayload;

/// Submit a VM config upgrade proposal
#[derive(Debug, Parser)]
Expand Down Expand Up @@ -62,9 +61,7 @@ impl CommandAction for UpgradeVMConfigProposalCommand {
let min_action_delay = get_dao_config(ctx.state())?.min_action_delay;
let vm_config_upgrade_proposal =
build_vm_config_upgrade_proposal(genesis_config.vm_config, min_action_delay);
ctx.state().build_and_execute_transaction(
opt.transaction_opts.clone(),
TransactionPayload::EntryFunction(vm_config_upgrade_proposal),
)
ctx.state()
.build_and_execute_transaction(opt.transaction_opts.clone(), vm_config_upgrade_proposal)
}
}
9 changes: 4 additions & 5 deletions executor/benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use starcoin_types::{
use starcoin_vm_types::genesis_config::StdlibVersion;
use starcoin_vm_types::token::stc;
use starcoin_vm_types::transaction::authenticator::AuthenticationKey;
use starcoin_vm_types::transaction::EntryFunction;
use std::sync::mpsc;
use std::sync::Arc;

Expand Down Expand Up @@ -128,13 +127,13 @@ impl TransactionGenerator {
for (j, account) in block.iter().enumerate() {
let txn = create_transaction(
self.sequence,
encode_create_account_script_function(
TransactionPayload::EntryFunction(encode_create_account_script_function(
StdlibVersion::Latest,
stc::stc_type_tag(),
&account.address,
AuthenticationKey::ed25519(account.public_key()),
init_account_balance as u128,
),
)),
self.net.time_service().now_secs() + j as u64 + 1,
&self.net,
);
Expand Down Expand Up @@ -285,12 +284,12 @@ pub fn run_benchmark(

fn create_transaction(
sequence_number: u64,
program: EntryFunction,
program: TransactionPayload,
expiration_timestamp_secs: u64,
net: &ChainNetwork,
) -> Transaction {
let signed_txn = create_signed_txn_with_association_account(
TransactionPayload::EntryFunction(program),
program,
sequence_number,
40_000_000,
1,
Expand Down
11 changes: 6 additions & 5 deletions executor/tests/executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ impl TStateView for NullStateView {
fn test_vm_version() {
let (chain_state, _net) = prepare_genesis();

let version_module_id = ModuleId::new(genesis_address(), Identifier::new("Version").unwrap());
let version_module_id =
ModuleId::new(genesis_address(), Identifier::new("stc_version").unwrap());
let mut value = starcoin_dev::playground::call_contract(
&chain_state,
version_module_id,
Expand All @@ -103,7 +104,7 @@ fn test_flexidag_config_get() {

let version_module_id = ModuleId::new(
genesis_address(),
Identifier::new("FlexiDagConfig").unwrap(),
Identifier::new("flexi_dag_config").unwrap(),
);
let mut value = starcoin_dev::playground::call_contract(
&chain_state,
Expand Down Expand Up @@ -159,7 +160,7 @@ fn test_consensus_config_get() -> Result<()> {

let module_id = ModuleId::new(
genesis_address(),
Identifier::new("ConsensusConfig").unwrap(),
Identifier::new("consensus_config").unwrap(),
);
let mut rets = starcoin_dev::playground::call_contract(
&chain_state,
Expand Down Expand Up @@ -582,7 +583,7 @@ fn test_validate_txn_args() -> Result<()> {
let action = EntryFunction::new(
ModuleId::new(
core_code_address(),
Identifier::new("TransferScript").unwrap(),
Identifier::new("transfer_scripts").unwrap(),
),
Identifier::new("peer_to_peer").unwrap(),
vec![stc_type_tag()],
Expand All @@ -603,7 +604,7 @@ fn test_validate_txn_args() -> Result<()> {
let action = EntryFunction::new(
ModuleId::new(
core_code_address(),
Identifier::new("TransferScripts").unwrap(),
Identifier::new("transfer_scripts").unwrap(),
),
Identifier::new("peer_to_peer_v2").unwrap(),
vec![stc_type_tag()],
Expand Down
5 changes: 0 additions & 5 deletions test-helper/src/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use starcoin_executor::execute_readonly_function;
use starcoin_logger::prelude::*;
use starcoin_state_api::ChainStateReader;
use starcoin_statedb::ChainStateDB;
use starcoin_transaction_builder::build_empty_script;
use starcoin_transaction_builder::encode_create_account_script_function;
use starcoin_types::account_address::AccountAddress;
use starcoin_types::account_config::{association_address, genesis_address, stc_type_tag};
Expand Down Expand Up @@ -439,10 +438,6 @@ pub fn execute_script_on_chain_config(
)
}

pub fn empty_txn_payload() -> TransactionPayload {
TransactionPayload::EntryFunction(build_empty_script())
}

pub fn dao_vote_test(
alice: &Account,
chain_state: &ChainStateDB,
Expand Down
8 changes: 5 additions & 3 deletions test-helper/src/txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ pub fn create_account_txn_sent_as_association(
) -> SignedUserTransaction {
let args = vec![
bcs_ext::to_bytes(new_account.address()).unwrap(),
bcs_ext::to_bytes(&new_account.auth_key().to_vec()).unwrap(),
bcs_ext::to_bytes(&initial_amount).unwrap(),
];

create_signed_txn_with_association_account(
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(core_code_address(), Identifier::new("Account").unwrap()),
Identifier::new("create_account_with_initial_amount").unwrap(),
ModuleId::new(
core_code_address(),
Identifier::new("transfer_scripts").unwrap(),
),
Identifier::new("peer_to_peer_v2").unwrap(),
vec![stc_type_tag()],
args,
)),
Expand Down
1 change: 0 additions & 1 deletion vm/framework/starcoin-framework/doc/dao.md
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,6 @@ extract proposal action to execute.
proposer_address: <b>address</b>,
proposal_id: u64,
): ActionT <b>acquires</b> <a href="dao.md#0x1_dao_Proposal">Proposal</a> {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"<a href="dao.md#0x1_dao_extract_proposal_action">dao::extract_proposal_action</a> | Entered"));
// Only executable proposal's action can be extracted.
<b>assert</b>!(
<a href="dao.md#0x1_dao_proposal_state">proposal_state</a>&lt;TokenT, ActionT&gt;(proposer_address, proposal_id) == <a href="dao.md#0x1_dao_EXECUTABLE">EXECUTABLE</a>,
Expand Down
Loading
Loading