Skip to content

Commit e281320

Browse files
committed
[move] removing public functions where unecessary (#206)
1 parent 5120e41 commit e281320

File tree

101 files changed

+1348
-11686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1348
-11686
lines changed

framework/cached-packages/src/libra_framework_sdk_builder.rs

Lines changed: 87 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ pub enum EntryFunctionCall {
136136
cap_update_table: Vec<u8>,
137137
},
138138

139+
/// User opts into burns being sent to community (recycle burn).
140+
/// default is false (burn is final).
141+
BurnSetSendCommunity {
142+
community: bool,
143+
},
144+
139145
/// Same as `publish_package` but as an entry function which can be called as a transaction. Because
140146
/// of current restrictions for txn parameters, the metadata needs to be passed in serialized form.
141147
CodePublishPackageTxn {
@@ -171,12 +177,6 @@ pub enum EntryFunctionCall {
171177
check_threshold: u64,
172178
},
173179

174-
DemoPrintThis {},
175-
176-
DemoSetMessage {
177-
message: Vec<u8>,
178-
},
179-
180180
DiemGovernanceAddApprovedScriptHashScript {
181181
proposal_id: u64,
182182
},
@@ -266,6 +266,8 @@ pub enum EntryFunctionCall {
266266
id: u64,
267267
},
268268

269+
EpochBoundarySmokeTriggerEpoch {},
270+
269271
/// Only a Voucher of the validator can flip the unjail bit.
270272
/// This is a way to make sure the validator is ready to rejoin.
271273
JailUnjailByVoucher {
@@ -475,13 +477,10 @@ pub enum EntryFunctionCall {
475477
epoch_expiry: u64,
476478
},
477479

478-
/// Creates a new resource account and rotates the authentication key to either
479-
/// the optional auth key if it is non-empty (though auth keys are 32-bytes)
480-
/// or the source accounts current auth key.
481-
ResourceAccountCreateResourceAccount {
482-
seed: Vec<u8>,
483-
optional_auth_key: Vec<u8>,
484-
},
480+
/// This fucntion initiates governance for the multisig. It is called by the sponsor address, and is only callable once.
481+
/// init_gov fails gracefully if the governance is already initialized.
482+
/// init_type will throw errors if the type is already initialized.
483+
SafeInitPaymentMultisig {},
485484

486485
SlowWalletSmokeTestVmUnlock {
487486
user_addr: AccountAddress,
@@ -634,6 +633,7 @@ impl EntryFunctionCall {
634633
new_public_key_bytes,
635634
cap_update_table,
636635
),
636+
BurnSetSendCommunity { community } => burn_set_send_community(community),
637637
CodePublishPackageTxn {
638638
metadata_serialized,
639639
code,
@@ -664,8 +664,6 @@ impl EntryFunctionCall {
664664
check_addresses,
665665
check_threshold,
666666
} => community_wallet_init_init_community(check_addresses, check_threshold),
667-
DemoPrintThis {} => demo_print_this(),
668-
DemoSetMessage { message } => demo_set_message(message),
669667
DiemGovernanceAddApprovedScriptHashScript { proposal_id } => {
670668
diem_governance_add_approved_script_hash_script(proposal_id)
671669
}
@@ -737,6 +735,7 @@ impl EntryFunctionCall {
737735
multisig_address,
738736
id,
739737
} => donor_voice_txs_vote_veto_tx(multisig_address, id),
738+
EpochBoundarySmokeTriggerEpoch {} => epoch_boundary_smoke_trigger_epoch(),
740739
JailUnjailByVoucher { addr } => jail_unjail_by_voucher(addr),
741740
LibraCoinClaimMintCapability {} => libra_coin_claim_mint_capability(),
742741
LibraCoinDelegateMintCapability { to } => libra_coin_delegate_mint_capability(to),
@@ -841,10 +840,7 @@ impl EntryFunctionCall {
841840
ProofOfFeePofUpdateBid { bid, epoch_expiry } => {
842841
proof_of_fee_pof_update_bid(bid, epoch_expiry)
843842
}
844-
ResourceAccountCreateResourceAccount {
845-
seed,
846-
optional_auth_key,
847-
} => resource_account_create_resource_account(seed, optional_auth_key),
843+
SafeInitPaymentMultisig {} => safe_init_payment_multisig(),
848844
SlowWalletSmokeTestVmUnlock {
849845
user_addr,
850846
unlocked,
@@ -1156,6 +1152,23 @@ pub fn account_rotate_authentication_key_with_rotation_capability(
11561152
))
11571153
}
11581154

1155+
/// User opts into burns being sent to community (recycle burn).
1156+
/// default is false (burn is final).
1157+
pub fn burn_set_send_community(community: bool) -> TransactionPayload {
1158+
TransactionPayload::EntryFunction(EntryFunction::new(
1159+
ModuleId::new(
1160+
AccountAddress::new([
1161+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1162+
0, 0, 0, 1,
1163+
]),
1164+
ident_str!("burn").to_owned(),
1165+
),
1166+
ident_str!("set_send_community").to_owned(),
1167+
vec![],
1168+
vec![bcs::to_bytes(&community).unwrap()],
1169+
))
1170+
}
1171+
11591172
/// Same as `publish_package` but as an entry function which can be called as a transaction. Because
11601173
/// of current restrictions for txn parameters, the metadata needs to be passed in serialized form.
11611174
pub fn code_publish_package_txn(
@@ -1267,36 +1280,6 @@ pub fn community_wallet_init_init_community(
12671280
))
12681281
}
12691282

1270-
pub fn demo_print_this() -> TransactionPayload {
1271-
TransactionPayload::EntryFunction(EntryFunction::new(
1272-
ModuleId::new(
1273-
AccountAddress::new([
1274-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1275-
0, 0, 0, 1,
1276-
]),
1277-
ident_str!("demo").to_owned(),
1278-
),
1279-
ident_str!("print_this").to_owned(),
1280-
vec![],
1281-
vec![],
1282-
))
1283-
}
1284-
1285-
pub fn demo_set_message(message: Vec<u8>) -> TransactionPayload {
1286-
TransactionPayload::EntryFunction(EntryFunction::new(
1287-
ModuleId::new(
1288-
AccountAddress::new([
1289-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1290-
0, 0, 0, 1,
1291-
]),
1292-
ident_str!("demo").to_owned(),
1293-
),
1294-
ident_str!("set_message").to_owned(),
1295-
vec![],
1296-
vec![bcs::to_bytes(&message).unwrap()],
1297-
))
1298-
}
1299-
13001283
pub fn diem_governance_add_approved_script_hash_script(proposal_id: u64) -> TransactionPayload {
13011284
TransactionPayload::EntryFunction(EntryFunction::new(
13021285
ModuleId::new(
@@ -1589,6 +1572,21 @@ pub fn donor_voice_txs_vote_veto_tx(
15891572
))
15901573
}
15911574

1575+
pub fn epoch_boundary_smoke_trigger_epoch() -> TransactionPayload {
1576+
TransactionPayload::EntryFunction(EntryFunction::new(
1577+
ModuleId::new(
1578+
AccountAddress::new([
1579+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1580+
0, 0, 0, 1,
1581+
]),
1582+
ident_str!("epoch_boundary").to_owned(),
1583+
),
1584+
ident_str!("smoke_trigger_epoch").to_owned(),
1585+
vec![],
1586+
vec![],
1587+
))
1588+
}
1589+
15921590
/// Only a Voucher of the validator can flip the unjail bit.
15931591
/// This is a way to make sure the validator is ready to rejoin.
15941592
pub fn jail_unjail_by_voucher(addr: AccountAddress) -> TransactionPayload {
@@ -2198,27 +2196,21 @@ pub fn proof_of_fee_pof_update_bid(bid: u64, epoch_expiry: u64) -> TransactionPa
21982196
))
21992197
}
22002198

2201-
/// Creates a new resource account and rotates the authentication key to either
2202-
/// the optional auth key if it is non-empty (though auth keys are 32-bytes)
2203-
/// or the source accounts current auth key.
2204-
pub fn resource_account_create_resource_account(
2205-
seed: Vec<u8>,
2206-
optional_auth_key: Vec<u8>,
2207-
) -> TransactionPayload {
2199+
/// This fucntion initiates governance for the multisig. It is called by the sponsor address, and is only callable once.
2200+
/// init_gov fails gracefully if the governance is already initialized.
2201+
/// init_type will throw errors if the type is already initialized.
2202+
pub fn safe_init_payment_multisig() -> TransactionPayload {
22082203
TransactionPayload::EntryFunction(EntryFunction::new(
22092204
ModuleId::new(
22102205
AccountAddress::new([
22112206
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22122207
0, 0, 0, 1,
22132208
]),
2214-
ident_str!("resource_account").to_owned(),
2209+
ident_str!("safe").to_owned(),
22152210
),
2216-
ident_str!("create_resource_account").to_owned(),
2211+
ident_str!("init_payment_multisig").to_owned(),
2212+
vec![],
22172213
vec![],
2218-
vec![
2219-
bcs::to_bytes(&seed).unwrap(),
2220-
bcs::to_bytes(&optional_auth_key).unwrap(),
2221-
],
22222214
))
22232215
}
22242216

@@ -2610,6 +2602,16 @@ mod decoder {
26102602
}
26112603
}
26122604

2605+
pub fn burn_set_send_community(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
2606+
if let TransactionPayload::EntryFunction(script) = payload {
2607+
Some(EntryFunctionCall::BurnSetSendCommunity {
2608+
community: bcs::from_bytes(script.args().get(0)?).ok()?,
2609+
})
2610+
} else {
2611+
None
2612+
}
2613+
}
2614+
26132615
pub fn code_publish_package_txn(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
26142616
if let TransactionPayload::EntryFunction(script) = payload {
26152617
Some(EntryFunctionCall::CodePublishPackageTxn {
@@ -2677,24 +2679,6 @@ mod decoder {
26772679
}
26782680
}
26792681

2680-
pub fn demo_print_this(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
2681-
if let TransactionPayload::EntryFunction(_script) = payload {
2682-
Some(EntryFunctionCall::DemoPrintThis {})
2683-
} else {
2684-
None
2685-
}
2686-
}
2687-
2688-
pub fn demo_set_message(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
2689-
if let TransactionPayload::EntryFunction(script) = payload {
2690-
Some(EntryFunctionCall::DemoSetMessage {
2691-
message: bcs::from_bytes(script.args().get(0)?).ok()?,
2692-
})
2693-
} else {
2694-
None
2695-
}
2696-
}
2697-
26982682
pub fn diem_governance_add_approved_script_hash_script(
26992683
payload: &TransactionPayload,
27002684
) -> Option<EntryFunctionCall> {
@@ -2872,6 +2856,16 @@ mod decoder {
28722856
}
28732857
}
28742858

2859+
pub fn epoch_boundary_smoke_trigger_epoch(
2860+
payload: &TransactionPayload,
2861+
) -> Option<EntryFunctionCall> {
2862+
if let TransactionPayload::EntryFunction(_script) = payload {
2863+
Some(EntryFunctionCall::EpochBoundarySmokeTriggerEpoch {})
2864+
} else {
2865+
None
2866+
}
2867+
}
2868+
28752869
pub fn jail_unjail_by_voucher(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
28762870
if let TransactionPayload::EntryFunction(script) = payload {
28772871
Some(EntryFunctionCall::JailUnjailByVoucher {
@@ -3222,14 +3216,9 @@ mod decoder {
32223216
}
32233217
}
32243218

3225-
pub fn resource_account_create_resource_account(
3226-
payload: &TransactionPayload,
3227-
) -> Option<EntryFunctionCall> {
3228-
if let TransactionPayload::EntryFunction(script) = payload {
3229-
Some(EntryFunctionCall::ResourceAccountCreateResourceAccount {
3230-
seed: bcs::from_bytes(script.args().get(0)?).ok()?,
3231-
optional_auth_key: bcs::from_bytes(script.args().get(1)?).ok()?,
3232-
})
3219+
pub fn safe_init_payment_multisig(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
3220+
if let TransactionPayload::EntryFunction(_script) = payload {
3221+
Some(EntryFunctionCall::SafeInitPaymentMultisig {})
32333222
} else {
32343223
None
32353224
}
@@ -3433,6 +3422,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
34333422
"account_rotate_authentication_key_with_rotation_capability".to_string(),
34343423
Box::new(decoder::account_rotate_authentication_key_with_rotation_capability),
34353424
);
3425+
map.insert(
3426+
"burn_set_send_community".to_string(),
3427+
Box::new(decoder::burn_set_send_community),
3428+
);
34363429
map.insert(
34373430
"code_publish_package_txn".to_string(),
34383431
Box::new(decoder::code_publish_package_txn),
@@ -3453,14 +3446,6 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
34533446
"community_wallet_init_init_community".to_string(),
34543447
Box::new(decoder::community_wallet_init_init_community),
34553448
);
3456-
map.insert(
3457-
"demo_print_this".to_string(),
3458-
Box::new(decoder::demo_print_this),
3459-
);
3460-
map.insert(
3461-
"demo_set_message".to_string(),
3462-
Box::new(decoder::demo_set_message),
3463-
);
34643449
map.insert(
34653450
"diem_governance_add_approved_script_hash_script".to_string(),
34663451
Box::new(decoder::diem_governance_add_approved_script_hash_script),
@@ -3517,6 +3502,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
35173502
"donor_voice_txs_vote_veto_tx".to_string(),
35183503
Box::new(decoder::donor_voice_txs_vote_veto_tx),
35193504
);
3505+
map.insert(
3506+
"epoch_boundary_smoke_trigger_epoch".to_string(),
3507+
Box::new(decoder::epoch_boundary_smoke_trigger_epoch),
3508+
);
35203509
map.insert(
35213510
"jail_unjail_by_voucher".to_string(),
35223511
Box::new(decoder::jail_unjail_by_voucher),
@@ -3634,8 +3623,8 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
36343623
Box::new(decoder::proof_of_fee_pof_update_bid),
36353624
);
36363625
map.insert(
3637-
"resource_account_create_resource_account".to_string(),
3638-
Box::new(decoder::resource_account_create_resource_account),
3626+
"safe_init_payment_multisig".to_string(),
3627+
Box::new(decoder::safe_init_payment_multisig),
36393628
);
36403629
map.insert(
36413630
"slow_wallet_smoke_test_vm_unlock".to_string(),

framework/libra-framework/sources/aggregator/aggregator_factory.move

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module diem_framework::aggregator_factory {
1212

1313
friend diem_framework::genesis;
1414
friend diem_framework::optional_aggregator;
15+
friend diem_framework::coin;
1516

1617
/// Aggregator factory is not published yet.
1718
const EAGGREGATOR_FACTORY_NOT_FOUND: u64 = 1;
@@ -45,7 +46,7 @@ module diem_framework::aggregator_factory {
4546

4647
/// This is currently a function closed for public. This can be updated in the future by on-chain governance
4748
/// to allow any signer to call.
48-
public fun create_aggregator(account: &signer, limit: u128): Aggregator acquires AggregatorFactory {
49+
public(friend) fun create_aggregator(account: &signer, limit: u128): Aggregator acquires AggregatorFactory {
4950
// Only Diem Framework (0x1) account can call this for now.
5051
system_addresses::assert_diem_framework(account);
5152
create_aggregator_internal(limit)

framework/libra-framework/sources/block.move

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module diem_framework::block {
7777

7878
/// Update the epoch interval.
7979
/// Can only be called as part of the Diem governance proposal process established by the DiemGovernance module.
80-
public fun update_epoch_interval_microsecs(
80+
public(friend) fun update_epoch_interval_microsecs(
8181
diem_framework: &signer,
8282
new_epoch_interval: u64,
8383
) acquires BlockResource {
@@ -200,6 +200,10 @@ module diem_framework::block {
200200

201201
/// Emit a `NewBlockEvent` event. This function will be invoked by write set script directly to generate the
202202
/// new block event for WriteSetPayload.
203+
// NOTE: This function is not `(friend)` because governance scripts need to
204+
// call it.
205+
// TODO: refactor diem_governance so that this can again have only
206+
// friend visibility.
203207
public fun emit_writeset_block_event(vm_signer: &signer, fake_block_hash: address) acquires BlockResource {
204208
system_addresses::assert_vm(vm_signer);
205209
let block_metadata_ref = borrow_global_mut<BlockResource>(@diem_framework);

framework/libra-framework/sources/chain_status.move

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module diem_framework::chain_status {
88

99
friend diem_framework::genesis;
1010

11+
//////// 0L ////////
12+
friend ol_framework::sacred_cows;
13+
1114
/// Marker to publish at the end of genesis.
1215
struct GenesisEndMarker has key {}
1316

@@ -37,12 +40,12 @@ module diem_framework::chain_status {
3740
}
3841

3942
/// Helper function to assert operating (not genesis) state.
40-
public fun assert_operating() {
43+
public(friend) fun assert_operating() {
4144
assert!(is_operating(), error::invalid_state(ENOT_OPERATING));
4245
}
4346

4447
/// Helper function to assert genesis state.
45-
public fun assert_genesis() {
48+
public(friend) fun assert_genesis() {
4649
assert!(is_genesis(), error::invalid_state(ENOT_OPERATING));
4750
}
4851
}

0 commit comments

Comments
 (0)