1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
pub mod account;
pub mod code;
pub mod event;
pub mod hash;
mod helpers;
pub mod signature;
pub mod transaction_context;
pub mod type_info;
pub mod util;
use move_deps::{
move_core_types::{account_address::AccountAddress, identifier::Identifier},
move_vm_runtime::native_functions::{make_table_from_iter, NativeFunctionTable},
};
pub mod status {
pub const NFE_EXPECTED_STRUCT_TYPE_TAG: u64 = 0x1;
pub const NFE_UNABLE_TO_PARSE_ADDRESS: u64 = 0x2;
}
#[derive(Debug, Clone)]
pub struct GasParameters {
pub account: account::GasParameters,
pub signature: signature::GasParameters,
pub hash: hash::GasParameters,
pub type_info: type_info::GasParameters,
pub util: util::GasParameters,
pub transaction_context: transaction_context::GasParameters,
pub code: code::GasParameters,
pub event: event::GasParameters,
}
impl GasParameters {
pub fn zeros() -> Self {
Self {
account: account::GasParameters {
create_address: account::CreateAddressGasParameters { base_cost: 0 },
create_signer: account::CreateSignerGasParameters { base_cost: 0 },
},
signature: signature::GasParameters {
bls12381_validate_pubkey: signature::Bls12381ValidatePubkeyGasParameters {
base_cost: 0,
},
ed25519_validate_pubkey: signature::Ed25519ValidatePubkeyGasParameters {
base_cost: 0,
},
ed25519_verify: signature::Ed25519VerifyGasParameters {
base_cost: 0,
unit_cost: 0,
},
secp256k1_ecdsa_recover: signature::Secp256k1ECDSARecoverGasParameters {
base_cost: 0,
},
bls12381_verify_signature: signature::Bls12381VerifySignatureGasParams {
base_cost: 0,
unit_cost: 0,
},
bls12381_aggregate_pop_verified_pubkeys:
signature::Bls12381AggregatePopVerifiedPubkeysGasParameters {
base_cost: 0,
per_pubkey_cost: 0,
},
bls12381_verify_proof_of_possession:
signature::Bls12381VerifyProofOfPosessionGasParameters { base_cost: 0 },
},
hash: hash::GasParameters {
sip_hash: hash::SipHashGasParameters {
base_cost: 0,
unit_cost: 0,
},
},
type_info: type_info::GasParameters {
type_of: type_info::TypeOfGasParameters {
base_cost: 0,
unit_cost: 0,
},
type_name: type_info::TypeNameGasParameters {
base_cost: 0,
unit_cost: 0,
},
},
util: util::GasParameters {
from_bytes: util::FromBytesGasParameters {
base_cost: 0,
unit_cost: 0,
},
},
transaction_context: transaction_context::GasParameters {
get_script_hash: transaction_context::GetScriptHashGasParameters { base_cost: 0 },
},
code: code::GasParameters {
request_publish: code::RequestPublishGasParameters {
base_cost: 0,
unit_cost: 0,
},
},
event: event::GasParameters {
write_to_event_store: event::WriteToEventStoreGasParameters { unit_cost: 0 },
},
}
}
}
pub fn all_natives(
framework_addr: AccountAddress,
gas_params: GasParameters,
) -> NativeFunctionTable {
let mut natives = vec![];
macro_rules! add_natives_from_module {
($module_name: expr, $natives: expr) => {
natives.extend(
$natives.map(|(func_name, func)| ($module_name.to_string(), func_name, func)),
);
};
}
add_natives_from_module!("account", account::make_all(gas_params.account));
add_natives_from_module!("signature", signature::make_all(gas_params.signature));
add_natives_from_module!("hash", hash::make_all(gas_params.hash));
add_natives_from_module!("type_info", type_info::make_all(gas_params.type_info));
add_natives_from_module!("util", util::make_all(gas_params.util));
add_natives_from_module!(
"transaction_context",
transaction_context::make_all(gas_params.transaction_context)
);
add_natives_from_module!("code", code::make_all(gas_params.code));
add_natives_from_module!("event", event::make_all(gas_params.event));
make_table_from_iter(framework_addr, natives)
}
pub fn patch_table_module(table: NativeFunctionTable) -> NativeFunctionTable {
table
.into_iter()
.map(|(m, _, f, i)| (m, Identifier::new("table").unwrap(), f, i))
.collect()
}