Skip to content

Commit

Permalink
[aptos-sdk-builder] reintroduce and update generated payloads
Browse files Browse the repository at this point in the history
Now that the former transaction-generator-builder is healthy, I've
reintroduced it. I've removed the unnecessary encode_ prefix and updated
the functions appropriately.
  • Loading branch information
davidiw committed Jul 23, 2022
1 parent 4e86f60 commit c90b56f
Show file tree
Hide file tree
Showing 50 changed files with 151 additions and 662 deletions.
4 changes: 2 additions & 2 deletions aptos-move/aptos-sdk-builder/examples/rust/script_fun_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use aptos_types::AccountAddress;
use framework::{encode_aptos_coin_transfer, ScriptFunctionCall};
use framework::{aptos_coin_transfer, ScriptFunctionCall};

fn demo_p2p_script_function() {
let payee = AccountAddress([
Expand All @@ -13,7 +13,7 @@ fn demo_p2p_script_function() {
let amount = 1234567;

// Now encode and decode a peer to peer transaction script function.
let payload = encode_aptos_coin_transfer(payee.clone(), amount);
let payload = aptos_coin_transfer(payee.clone(), amount);
let function_call = ScriptFunctionCall::decode(&payload);
match function_call {
Some(ScriptFunctionCall::AptosCoinTransfer { amount: a, to: p }) => {
Expand Down
7 changes: 4 additions & 3 deletions aptos-move/aptos-sdk-builder/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub fn output(out: &mut dyn Write, abis: &[ScriptABI], local_types: bool) -> Res
}

write!(emitter.out, "mod decoder {{")?;
write!(emitter.out, " use super::*;")?;
for abi in abis {
emitter.output_script_decoder_function(abi)?;
}
Expand Down Expand Up @@ -385,7 +386,7 @@ pub fn decode(script: &Script) -> Option<ScriptCall> {{
/// Try to recognize an Aptos `TransactionPayload` and convert it into a structured object `ScriptFunctionCall`.
pub fn decode(payload: &TransactionPayload) -> Option<ScriptFunctionCall> {{
if let TransactionPayload::ScriptFunction(script) = payload {{
match SCRIPT_FUNCTION_DECODER_MAP.get(&format!("{{}}{{}}", {}, {})) {{
match SCRIPT_FUNCTION_DECODER_MAP.get(&format!("{{}}_{{}}", {}, {})) {{
Some(decoder) => decoder(payload),
None => None,
}}
Expand Down Expand Up @@ -558,7 +559,7 @@ TransactionPayload::ScriptFunction(ScriptFunction {{
//
writeln!(
self.out,
"\nfn {}_{}(payload: &TransactionPayload) -> Option<ScriptFunctionCall> {{",
"\npub fn {}_{}(payload: &TransactionPayload) -> Option<ScriptFunctionCall> {{",
abi.module_name().name().to_string().to_snake_case(),
abi.name(),
)?;
Expand Down Expand Up @@ -617,7 +618,7 @@ TransactionPayload::ScriptFunction(ScriptFunction {{
) -> Result<()> {
writeln!(
self.out,
"\nfn {}_script({}script: &Script) -> Option<ScriptCall> {{",
"\npub fn {}_script({}script: &Script) -> Option<ScriptCall> {{",
abi.name(),
// fix warning "unused variable"
if abi.ty_args().is_empty() && abi.args().is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/aptos-sdk-builder/tests/generation.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use aptos_sdk_builder as buildgen;
use aptos_types::transaction::ScriptABI;
use cached_framework_packages::abis;
use serde_generate as serdegen;
use serde_generate::SourceInstaller as _;
use serde_reflection::Registry;
use std::{io::Write, process::Command};
use tempfile::tempdir;
use aptos_sdk_builder as buildgen;

fn get_aptos_registry() -> Registry {
let path = "../../testsuite/generate-format/tests/staged/aptos.yaml";
Expand Down
10 changes: 4 additions & 6 deletions aptos-move/e2e-tests/src/common_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ pub fn create_account_txn(
) -> SignedTransaction {
sender
.transaction()
.payload(aptos_stdlib::encode_account_create_account(
*new_account.address(),
))
.payload(aptos_stdlib::account_create_account(*new_account.address()))
.sequence_number(seq_num)
.sign()
}
Expand All @@ -64,7 +62,7 @@ pub fn peer_to_peer_txn(
// get a SignedTransaction
sender
.transaction()
.payload(aptos_stdlib::encode_aptos_coin_transfer(
.payload(aptos_stdlib::aptos_coin_transfer(
*receiver.address(),
transfer_amount,
))
Expand All @@ -76,7 +74,7 @@ pub fn peer_to_peer_txn(
pub fn rotate_key_txn(sender: &Account, new_key_hash: Vec<u8>, seq_num: u64) -> SignedTransaction {
sender
.transaction()
.payload(aptos_stdlib::encode_account_rotate_authentication_key(
.payload(aptos_stdlib::account_rotate_authentication_key(
new_key_hash,
))
.sequence_number(seq_num)
Expand All @@ -87,7 +85,7 @@ pub fn rotate_key_txn(sender: &Account, new_key_hash: Vec<u8>, seq_num: u64) ->
pub fn raw_rotate_key_txn(sender: &Account, new_key_hash: Vec<u8>, seq_num: u64) -> RawTransaction {
sender
.transaction()
.payload(aptos_stdlib::encode_account_rotate_authentication_key(
.payload(aptos_stdlib::account_rotate_authentication_key(
new_key_hash,
))
.sequence_number(seq_num)
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-tests/src/on_chain_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn set_aptos_version(executor: &mut FakeExecutor, version: Version) {
let account = Account::new_genesis_account(aptos_root_address());
let txn = account
.transaction()
.payload(aptos_stdlib::encode_version_set_version(version.major))
.payload(aptos_stdlib::version_set_version(version.major))
.sequence_number(0)
.sign();
executor.new_block();
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn upgrade_df(
executor.execute_and_apply(
dr_account
.transaction()
.payload(aptos_stdlib::encode_version_set_version(version_number))
.payload(aptos_stdlib::version_set_version(version_number))
.sequence_number(*dr_seqno)
.sign(),
);
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-testsuite/src/tests/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn mint_to_new_account() {
let mint_amount = TXN_RESERVED;
let output = executor.execute_transaction(
root.transaction()
.payload(aptos_stdlib::encode_aptos_coin_mint(
.payload(aptos_stdlib::aptos_coin_mint(
*new_account.address(),
mint_amount,
))
Expand Down
4 changes: 2 additions & 2 deletions aptos-move/e2e-testsuite/src/tests/on_chain_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn initial_aptos_version() {
println!("@@@@@@@@@@@@ account {:?}", account);
let txn = account
.transaction()
.payload(aptos_stdlib::encode_version_set_version(test_env.version_number + 1))
.payload(aptos_stdlib::version_set_version(test_env.version_number + 1))
.sequence_number(test_env.dr_sequence_number)
.sign();
println!("@@@@@@@@@@@@ txn {:?}", txn);
Expand Down Expand Up @@ -56,7 +56,7 @@ fn drop_txn_after_reconfiguration() {
let account = test_env.dr_account;
let txn = account
.transaction()
.payload(aptos_stdlib::encode_version_set_version(test_env.version_number + 1))
.payload(aptos_stdlib::version_set_version(test_env.version_number + 1))
.sequence_number(test_env.dr_sequence_number)
.sign();
executor.new_block();
Expand Down
6 changes: 3 additions & 3 deletions aptos-move/e2e-testsuite/src/tests/verify_txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn verify_signature() {
executor.add_account_data(&sender);
// Generate a new key pair to try and sign things with.
let private_key = Ed25519PrivateKey::generate_for_testing();
let program = aptos_stdlib::encode_aptos_coin_transfer(
let program = aptos_stdlib::aptos_coin_transfer(
*sender.address(),
100,
);
Expand Down Expand Up @@ -170,7 +170,7 @@ fn verify_reserved_sender() {
executor.add_account_data(&sender);
// Generate a new key pair to try and sign things with.
let private_key = Ed25519PrivateKey::generate_for_testing();
let program = aptos_stdlib::encode_aptos_coin_transfer(
let program = aptos_stdlib::aptos_coin_transfer(
*sender.address(),
100,
);
Expand Down Expand Up @@ -210,7 +210,7 @@ fn verify_simple_payment() {
let txn = sender
.account()
.transaction()
.payload(aptos_stdlib::encode_aptos_coin_transfer(*receiver.address(), transfer_amount))
.payload(aptos_stdlib::aptos_coin_transfer(*receiver.address(), transfer_amount))
.sequence_number(10)
.sign();
assert_eq!(executor.verify_transaction(txn).status(), None);
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/cached-packages/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
no_check_layout_compatibility: false,
no_build_docs: false,
with_diagram: false,
no_script_builder: true, // TODO: consider bringing this back
no_script_builder: false,
no_script_abis: false,
no_errmap: false,
package: PathBuf::from("aptos-framework"),
Expand Down
28 changes: 7 additions & 21 deletions aptos-move/framework/cached-packages/src/aptos_stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,15 @@

#![allow(unused_imports)]

use aptos_types::{
account_address::AccountAddress,
transaction::{Script, ScriptFunction, TransactionArgument, TransactionPayload, VecBytes},
utility_coin::APTOS_COIN_TYPE,
};
use move_deps::move_core_types::language_storage::{StructTag, TypeTag};
use move_deps::move_core_types::{ident_str, language_storage::ModuleId};

pub use crate::generated_aptos_txn_builder::*;

/* Currently the generated builders are checked in as source.
include!(concat!(
concat!(env!("OUT_DIR"), "/framework"),
"/transaction_script_builder.rs"
"/aptos_sdk_builder.rs",
));
*/

pub fn encode_aptos_coin_transfer(to: AccountAddress, amount: u64) -> TransactionPayload {
TransactionPayload::ScriptFunction(ScriptFunction::new(
ModuleId::new(AccountAddress::ONE, ident_str!("coin").to_owned()),
ident_str!("transfer").to_owned(),
vec![APTOS_COIN_TYPE.clone()],
vec![bcs::to_bytes(&to).unwrap(), bcs::to_bytes(&amount).unwrap()],
))
pub fn aptos_coin_transfer(to: AccountAddress, amount: u64) -> TransactionPayload {
coin_transfer(
aptos_types::utility_coin::APTOS_COIN_TYPE.clone(),
to,
amount,
)
}
19 changes: 0 additions & 19 deletions aptos-move/framework/cached-packages/src/aptos_token_stdlib.rs

This file was deleted.

Loading

0 comments on commit c90b56f

Please sign in to comment.