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

[gen]update golang gen code #3007

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions etc/starcoin_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@ ArgumentABI:
TYPENAME: TypeTag
AuthenticationKey:
NEWTYPESTRUCT: BYTES
BlockHeader:
STRUCT:
- parent_hash:
TYPENAME: HashValue
- timestamp: U64
- number: U64
- author:
TYPENAME: AccountAddress
- author_auth_key:
OPTION:
TYPENAME: AuthenticationKey
- txn_accumulator_root:
TYPENAME: HashValue
- block_accumulator_root:
TYPENAME: HashValue
- state_root:
TYPENAME: HashValue
- gas_used: U64
- difficulty:
TUPLEARRAY:
CONTENT: U8
SIZE: 32
- body_hash:
TYPENAME: HashValue
- chain_id:
TYPENAME: ChainId
- nonce: U32
- extra:
TYPENAME: BlockHeaderExtra
BlockHeaderExtra:
NEWTYPESTRUCT:
TUPLEARRAY:
CONTENT: U8
SIZE: 4
BlockMetadata:
STRUCT:
- parent_hash:
Expand Down Expand Up @@ -241,6 +275,18 @@ TransactionArgument:
5:
Bool:
NEWTYPE: BOOL
6:
VecU128:
NEWTYPE:
TYPENAME: VecU128
7:
VecAccountAddress:
NEWTYPE:
TYPENAME: VecAccountAddress
8:
VecBytes:
NEWTYPE:
TYPENAME: VecBytes
TransactionAuthenticator:
ENUM:
0:
Expand Down Expand Up @@ -311,6 +357,16 @@ WithdrawCapabilityResource:
STRUCT:
- account_address:
TYPENAME: AccountAddress
VecBytes:
NEWTYPESTRUCT:
SEQ: BYTES
VecAccountAddress:
NEWTYPESTRUCT:
SEQ:
TYPENAME: AccountAddress
VecU128:
NEWTYPESTRUCT:
SEQ: U128
WriteOp:
ENUM:
0:
Expand Down
56 changes: 0 additions & 56 deletions vm/transaction-builder-generator/examples/java/StdlibDemo.java

This file was deleted.

46 changes: 37 additions & 9 deletions vm/transaction-builder-generator/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ fn quote_type_as_format(type_tag: &TypeTag) -> Format {
Address => Format::TypeName("AccountAddress".into()),
Vector(type_tag) => match type_tag.as_ref() {
U8 => Format::Bytes,
U128 => Format::TypeName("VecU128".into()),
Address => Format::TypeName("VecAccountAddress".into()),
Vector(type_tag) => match type_tag.as_ref() {
U8 => Format::TypeName("VecBytes".into()),
_ => type_not_allowed(type_tag),
},
_ => type_not_allowed(type_tag),
},

Struct(_) | Signer => type_not_allowed(type_tag),
}
}
Expand Down Expand Up @@ -79,23 +84,39 @@ pub(crate) fn mangle_type(type_tag: &TypeTag) -> String {
use TypeTag::*;
match type_tag {
Bool => "bool".into(),
U8 => "st.uint8".into(),
U64 => "st.uint64".into(),
U128 => "st.uint128".into(),
Address => "starcoin_types.AccountAddress".into(),
U8 => "u8".into(),
U64 => "u64".into(),
U128 => "u128".into(),
Address => "address".into(),
Vector(type_tag) => match type_tag.as_ref() {
U8 => "bytes".into(),
U8 => "u8vector".into(),
Address => "vecaccountaddress".into(),
U128 => "vecu128".into(),
Vector(type_tag) => {
if type_tag.as_ref() == &U8 {
"vecbytes".into()
} else {
type_not_allowed(type_tag)
}
}
_ => type_not_allowed(type_tag),
},

Struct(_) | Signer => type_not_allowed(type_tag),
}
}

pub(crate) fn get_external_definitions(diem_types: &str) -> serde_generate::ExternalDefinitions {
let definitions = vec![(
diem_types,
vec!["AccountAddress", "TypeTag", "Script", "TransactionArgument"],
vec![
"AccountAddress",
"TypeTag",
"Script",
"TransactionArgument",
"VecBytes",
"VecU128",
"VecAccountAddress",
],
)];
definitions
.into_iter()
Expand All @@ -108,7 +129,7 @@ pub(crate) fn get_external_definitions(diem_types: &str) -> serde_generate::Exte
.collect()
}

pub(crate) fn get_required_decoding_helper_types(abis: &[ScriptABI]) -> BTreeSet<&TypeTag> {
pub(crate) fn get_required_helper_types(abis: &[ScriptABI]) -> BTreeSet<&TypeTag> {
let mut required_types = BTreeSet::new();
for abi in abis {
for arg in abi.args() {
Expand All @@ -119,6 +140,13 @@ pub(crate) fn get_required_decoding_helper_types(abis: &[ScriptABI]) -> BTreeSet
required_types
}

pub(crate) fn filter_transaction_scripts(abis: &[ScriptABI]) -> Vec<ScriptABI> {
abis.iter()
.cloned()
.filter(|abi| abi.is_transaction_script_abi())
.collect()
}

pub(crate) fn transaction_script_abis(abis: &[ScriptABI]) -> Vec<TransactionScriptABI> {
abis.iter()
.cloned()
Expand Down
Loading