Skip to content

Commit 7009361

Browse files
committed
[move] set slow wallet entry function (#143)
1 parent 61f594d commit 7009361

File tree

22 files changed

+10492
-10418
lines changed

22 files changed

+10492
-10418
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
- synchronize
1313
branches:
1414
- "release**"
15-
- "main"
15+
- "main**"
1616
env:
1717
DIEM_FORGE_NODE_BIN_PATH: ${{github.workspace}}/diem-node
1818
LIBRA_CI: 1
@@ -166,4 +166,4 @@ jobs:
166166
- name: rescue
167167
if: always()
168168
working-directory: ./tools/rescue
169-
run: RUST_MIN_STACK=104857600 cargo test --no-fail-fast -- --test-threads=1
169+
run: RUST_MIN_STACK=104857600 cargo test --no-fail-fast -- --test-threads=1

.github/workflows/cleanliness.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- synchronize
1212
branches:
1313
- 'release**'
14-
- 'main'
14+
- 'main**'
1515
env:
1616
DIEM_FORGE_NODE_BIN_PATH: ${{github.workspace}}/diem-node
1717
LIBRA_CI: 1

.github/workflows/formal.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- synchronize
1212
branches:
1313
- 'release**'
14-
- 'main'
14+
- 'main**'
1515
env:
1616
DOTNET_ROOT: "/home/runner/.dotnet"
1717
Z3_EXE: "/home/runner/bin/z3"

.github/workflows/move.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
- synchronize
1313
branches:
1414
- 'release**'
15-
- 'main'
15+
- 'main**'
1616

1717
jobs:
1818
functional-tests:

framework/cached-packages/src/libra_framework_sdk_builder.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ pub enum EntryFunctionCall {
466466
transferred: u64,
467467
},
468468

469+
/// Users can change their account to slow, by calling the entry function
470+
/// Warning: this is permanent for the account. There's no way to
471+
/// reverse a "slow wallet".
472+
SlowWalletUserSetSlow {},
473+
469474
/// Initialize the validator account and give ownership to the signing account
470475
/// except it leaves the ValidatorConfig to be set by another entity.
471476
/// Note: this triggers setting the operator and owner, set it to the account's address
@@ -811,6 +816,7 @@ impl EntryFunctionCall {
811816
unlocked,
812817
transferred,
813818
} => slow_wallet_smoke_test_vm_unlock(user_addr, unlocked, transferred),
819+
SlowWalletUserSetSlow {} => slow_wallet_user_set_slow(),
814820
StakeInitializeStakeOwner {
815821
initial_stake_amount,
816822
operator,
@@ -2128,6 +2134,24 @@ pub fn slow_wallet_smoke_test_vm_unlock(
21282134
))
21292135
}
21302136

2137+
/// Users can change their account to slow, by calling the entry function
2138+
/// Warning: this is permanent for the account. There's no way to
2139+
/// reverse a "slow wallet".
2140+
pub fn slow_wallet_user_set_slow() -> TransactionPayload {
2141+
TransactionPayload::EntryFunction(EntryFunction::new(
2142+
ModuleId::new(
2143+
AccountAddress::new([
2144+
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,
2145+
0, 0, 0, 1,
2146+
]),
2147+
ident_str!("slow_wallet").to_owned(),
2148+
),
2149+
ident_str!("user_set_slow").to_owned(),
2150+
vec![],
2151+
vec![],
2152+
))
2153+
}
2154+
21312155
/// Initialize the validator account and give ownership to the signing account
21322156
/// except it leaves the ValidatorConfig to be set by another entity.
21332157
/// Note: this triggers setting the operator and owner, set it to the account's address
@@ -3078,6 +3102,14 @@ mod decoder {
30783102
}
30793103
}
30803104

3105+
pub fn slow_wallet_user_set_slow(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
3106+
if let TransactionPayload::EntryFunction(_script) = payload {
3107+
Some(EntryFunctionCall::SlowWalletUserSetSlow {})
3108+
} else {
3109+
None
3110+
}
3111+
}
3112+
30813113
pub fn stake_initialize_stake_owner(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
30823114
if let TransactionPayload::EntryFunction(script) = payload {
30833115
Some(EntryFunctionCall::StakeInitializeStakeOwner {
@@ -3450,6 +3482,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
34503482
"slow_wallet_smoke_test_vm_unlock".to_string(),
34513483
Box::new(decoder::slow_wallet_smoke_test_vm_unlock),
34523484
);
3485+
map.insert(
3486+
"slow_wallet_user_set_slow".to_string(),
3487+
Box::new(decoder::slow_wallet_user_set_slow),
3488+
);
34533489
map.insert(
34543490
"stake_initialize_stake_owner".to_string(),
34553491
Box::new(decoder::stake_initialize_stake_owner),

framework/libra-framework/sources/ol_sources/ol_account.move

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ module ol_framework::ol_account {
188188
assert!(amount < limit, error::invalid_state(EINSUFFICIENT_BALANCE));
189189

190190
let coin = coin::withdraw_with_capability(cap, amount);
191+
slow_wallet::maybe_track_unlocked_withdraw(payer, amount);
192+
191193
// the outgoing coins should trigger an update on this account
192194
// order matters here
193195
maybe_update_burn_tracker_impl(payer);
@@ -202,16 +204,15 @@ module ol_framework::ol_account {
202204
assume !system_addresses::signer_is_ol_root(sender);
203205
assume chain_status::is_operating();
204206
};
205-
// never abort when its a system address
206-
// if (system_addresses::signer_is_ol_root(sender)) return
207-
// coin::zero<LibraCoin>(); // and VM needs to figure this out.
208207

209208
let addr = signer::address_of(sender);
210209
assert!(amount > 0, error::invalid_argument(EZERO_TRANSFER));
211210

212211
let limit = slow_wallet::unlocked_amount(addr);
213212
assert!(amount <= limit, error::invalid_state(EINSUFFICIENT_BALANCE));
214213
let coin = coin::withdraw<LibraCoin>(sender, amount);
214+
slow_wallet::maybe_track_unlocked_withdraw(addr, amount);
215+
215216
// the outgoing coins should trigger an update on this account
216217
// order matters here
217218
maybe_update_burn_tracker_impl(addr);
@@ -235,7 +236,7 @@ module ol_framework::ol_account {
235236
assert!(coin::is_account_registered<LibraCoin>(recipient), error::invalid_argument(EACCOUNT_NOT_REGISTERED_FOR_GAS));
236237

237238
// must track the slow wallet on both sides of the transfer
238-
slow_wallet::maybe_track_slow_transfer(payer, recipient, amount);
239+
// slow_wallet::maybe_track_slow_transfer(payer, recipient, amount);
239240

240241
// maybe track cumulative deposits if this is a donor directed wallet
241242
// or other wallet which tracks cumulative payments.
@@ -324,10 +325,6 @@ module ol_framework::ol_account {
324325

325326
}
326327

327-
// public fun withdraw_with_capability(cap: &WithdrawCapability, amount: u64): Coin<LibraCoin> {
328-
// coin::withdraw_with_capability(cap, amount)
329-
// }
330-
331328
//////// 0L ////////
332329

333330
#[view]

framework/libra-framework/sources/ol_sources/slow_wallet.move

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ module ol_framework::slow_wallet {
9898
}
9999
}
100100

101+
/// Users can change their account to slow, by calling the entry function
102+
/// Warning: this is permanent for the account. There's no way to
103+
/// reverse a "slow wallet".
104+
public entry fun user_set_slow(sig: &signer) acquires SlowWalletList {
105+
set_slow(sig);
106+
}
107+
108+
/// implementation of setting slow wallet, allows contracts to call.
101109
public fun set_slow(sig: &signer) acquires SlowWalletList {
102110
assert!(exists<SlowWalletList>(@ol_framework), error::invalid_argument(EGENESIS_ERROR));
103111

framework/libra-framework/sources/ol_sources/tests/slow_wallet.test.move

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module ol_framework::test_slow_wallet {
1616
use ol_framework::rewards;
1717
use std::vector;
1818

19-
// use diem_std::debug::print;
19+
use diem_std::debug::print;
2020

2121
#[test(root = @ol_framework)]
2222
// we are testing that genesis creates the needed struct
@@ -118,6 +118,10 @@ module ol_framework::test_slow_wallet {
118118
// slow transfer
119119
let b_balance = coin::balance<LibraCoin>(@0x456);
120120
assert!(b_balance == transfer_amount, 735704);
121+
print(&alice_init_balance);
122+
print(&transfer_amount);
123+
print(&slow_wallet::unlocked_amount(@0x123));
124+
121125
assert!(slow_wallet::unlocked_amount(@0x123) == (alice_init_balance - transfer_amount), 735705);
122126
assert!(slow_wallet::unlocked_amount(@0x456) == transfer_amount, 735706);
123127

framework/releases/head.mrb

134 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)