@@ -70,19 +70,6 @@ pub mod pallet {
7070 type BalanceFromBalancePallet < T > = <T as pallet_balances:: Config >:: Balance ;
7171 type Date = i64 ;
7272
73- #[ derive( Encode , Decode , Debug , Default , Clone , Eq , PartialEq ) ]
74- #[ cfg_attr( feature = "std" , derive( ) ) ]
75- pub struct BondedDHXForAccountData < U , V , W > {
76- pub account_id : U ,
77- pub bonded_dhx_current : V ,
78- pub requestor_account_id : W ,
79- }
80-
81- type BondedData < T > = BondedDHXForAccountData <
82- <T as frame_system:: Config >:: AccountId ,
83- BalanceOf < T > ,
84- <T as frame_system:: Config >:: AccountId ,
85- > ;
8673
8774 /// Configure the pallet by specifying the parameters and types on which it depends.
8875 #[ pallet:: config]
@@ -107,8 +94,11 @@ pub mod pallet {
10794 #[ pallet:: storage]
10895 #[ pallet:: getter( fn bonded_dhx_of_account_for_date) ]
10996 pub ( super ) type BondedDHXForAccountForDate < T : Config > = StorageMap < _ , Blake2_128Concat ,
110- Date ,
111- BondedData < T >
97+ (
98+ Date ,
99+ T :: AccountId ,
100+ ) ,
101+ BalanceOf < T > ,
112102 > ;
113103
114104 #[ pallet:: storage]
@@ -279,9 +269,9 @@ pub mod pallet {
279269 /// \[cooling_off_period_days\]
280270 SetCoolingOffPeriodDaysStored ( u32 ) ,
281271
282- /// Storage of the bonded DHX of an account on a specific date by a requesting origin account .
283- /// \[date, amount_dhx_bonded, account_dhx_bonded, sender \]
284- SetBondedDHXOfAccountForDateStored ( Date , BondedData < T > , T :: AccountId , T :: AccountId ) ,
272+ /// Storage of the bonded DHX of an account on a specific date.
273+ /// \[date, amount_dhx_bonded, account_dhx_bonded\]
274+ SetBondedDHXOfAccountForDateStored ( Date , BalanceOf < T > , T :: AccountId ) ,
285275
286276 /// Storage of the default daily reward allowance in DHX by an origin account.
287277 /// \[amount_dhx, sender\]
@@ -438,8 +428,8 @@ pub mod pallet {
438428 // Test with 2x registered miners each with values like `25133000000000000000000u128`, which is over
439429 // half of 5000 DHX daily allowance (of 2500 DHX), but in that case we split the rewards
440430 // (i.e. 25,133 DHX locked at 10:1 gives 2513 DHX reward)
441- let mut locks_first_amount_as_u128 = 25_133_000_000_000_000_000_000u128 ;
442431
432+ let mut locks_first_amount_as_u128 = 25_133_000_000_000_000_000_000u128 ;
443433 let locked_vec = <pallet_balances:: Pallet < T > >:: locks ( miner. clone ( ) ) . into_inner ( ) ;
444434 if locked_vec. len ( ) != 0 {
445435 let locks_first_amount: <T as pallet_balances:: Config >:: Balance =
@@ -476,6 +466,22 @@ pub mod pallet {
476466 // reasons: Reasons::Misc,
477467 // },
478468
469+ let bonded_dhx_current_u128;
470+ let _bonded_dhx_current_u128 = Self :: set_bonded_dhx_of_account_for_date (
471+ miner. clone ( ) ,
472+ locks_first_amount_as_u128. clone ( )
473+ ) ;
474+ match _bonded_dhx_current_u128 {
475+ Err ( _e) => {
476+ log:: error!( "Unable to set_bonded_dhx_of_account_for_date" ) ;
477+ return 0 ;
478+ } ,
479+ Ok ( ref x) => {
480+ bonded_dhx_current_u128 = x;
481+ }
482+ }
483+ log:: info!( "set_bonded_dhx_of_account_for_date: {:?} {:?}" , start_of_requested_date_millis. clone( ) , bonded_dhx_current_u128. clone( ) ) ;
484+
479485 // TODO - refactor to use `convert_balance_to_u128` instead of all the following
480486 let min_bonded_dhx_daily;
481487 let min_bonded_dhx_daily_to_try = <MinBondedDHXDaily < T > >:: get ( ) ;
@@ -1281,59 +1287,6 @@ pub mod pallet {
12811287 Ok ( ( ) )
12821288 }
12831289
1284- // customised by governance at any time. this function allows us to change it each year
1285- // https://docs.google.com/spreadsheets/d/1W2AzOH9Cs9oCR8UYfYCbpmd9X7hp-USbYXL7AuwMY_Q/edit#gid=970997021
1286- #[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 1 ) ) ]
1287- pub fn set_bonded_dhx_of_account_for_date ( origin : OriginFor < T > , account_id : T :: AccountId ) -> DispatchResult {
1288- let _who = ensure_signed ( origin) ?;
1289-
1290- // Note: we DO need the following as we're using the current timestamp, rather than a function parameter.
1291- let timestamp: <T as pallet_timestamp:: Config >:: Moment = <pallet_timestamp:: Pallet < T > >:: get ( ) ;
1292- let requested_date_as_u64 = Self :: convert_moment_to_u64_in_milliseconds ( timestamp. clone ( ) ) ?;
1293- log:: info!( "set_bonded_dhx_of_account_for_date - requested_date_as_u64: {:?}" , requested_date_as_u64. clone( ) ) ;
1294-
1295- // convert the requested date/time to the start of that day date/time to signify that date for lookup
1296- // i.e. 21 Apr @ 1420 -> 21 Apr @ 0000
1297- let start_of_requested_date_millis = Self :: convert_u64_in_milliseconds_to_start_of_date ( requested_date_as_u64. clone ( ) ) ?;
1298-
1299- // TODO - fetch from democracy or elections
1300- let bonded_dhx_current_u128 = 1000u128 ;
1301-
1302- let bonded_dhx_current;
1303- let _bonded_dhx_current = Self :: convert_u128_to_balance ( bonded_dhx_current_u128. clone ( ) ) ;
1304- match _bonded_dhx_current {
1305- Err ( _e) => {
1306- log:: error!( "Unable to convert u128 to balance for bonded_dhx_current" ) ;
1307- return Err ( DispatchError :: Other ( "Unable to convert u128 to balance for bonded_dhx_current" ) ) ;
1308- } ,
1309- Ok ( ref x) => {
1310- bonded_dhx_current = x;
1311- }
1312- }
1313-
1314- let bonded_data: BondedData < T > = BondedDHXForAccountData {
1315- account_id : account_id. clone ( ) ,
1316- bonded_dhx_current : bonded_dhx_current. clone ( ) ,
1317- requestor_account_id : _who. clone ( ) ,
1318- } ;
1319-
1320- // Update storage. Override the default that may have been set in on_initialize
1321- <BondedDHXForAccountForDate < T > >:: insert ( start_of_requested_date_millis. clone ( ) , & bonded_data) ;
1322- log:: info!( "set_bonded_dhx_of_account_for_date - account_id: {:?}" , & account_id) ;
1323- log:: info!( "set_bonded_dhx_of_account_for_date - bonded_data: {:?}" , & bonded_data) ;
1324-
1325- // Emit an event.
1326- Self :: deposit_event ( Event :: SetBondedDHXOfAccountForDateStored (
1327- start_of_requested_date_millis. clone ( ) ,
1328- bonded_data. clone ( ) ,
1329- account_id. clone ( ) ,
1330- _who. clone ( ) ,
1331- ) ) ;
1332-
1333- // Return a successful DispatchResultWithPostInfo
1334- Ok ( ( ) )
1335- }
1336-
13371290 // TODO: we need to change this in future so it is only modifiable by governance,
13381291 // rather than just any user
13391292 #[ pallet:: weight( 10_000 + T :: DbWeight :: get( ) . writes( 1 ) ) ]
@@ -1526,5 +1479,51 @@ pub mod pallet {
15261479
15271480 return Ok ( blocknumber_u64) ;
15281481 }
1482+
1483+ fn set_bonded_dhx_of_account_for_date ( account_id : T :: AccountId , bonded_dhx : u128 ) -> Result < u128 , DispatchError > {
1484+ // Note: we DO need the following as we're using the current timestamp, rather than a function parameter.
1485+ let timestamp: <T as pallet_timestamp:: Config >:: Moment = <pallet_timestamp:: Pallet < T > >:: get ( ) ;
1486+ let requested_date_as_u64 = Self :: convert_moment_to_u64_in_milliseconds ( timestamp. clone ( ) ) ?;
1487+ log:: info!( "set_bonded_dhx_of_account_for_date - requested_date_as_u64: {:?}" , requested_date_as_u64. clone( ) ) ;
1488+
1489+ // convert the requested date/time to the start of that day date/time to signify that date for lookup
1490+ // i.e. 21 Apr @ 1420 -> 21 Apr @ 0000
1491+ let start_of_requested_date_millis = Self :: convert_u64_in_milliseconds_to_start_of_date ( requested_date_as_u64. clone ( ) ) ?;
1492+
1493+ let bonded_dhx_current_u128 = bonded_dhx. clone ( ) ;
1494+
1495+ let bonded_dhx_current;
1496+ let _bonded_dhx_current = Self :: convert_u128_to_balance ( bonded_dhx_current_u128. clone ( ) ) ;
1497+ match _bonded_dhx_current {
1498+ Err ( _e) => {
1499+ log:: error!( "Unable to convert u128 to balance for bonded_dhx_current" ) ;
1500+ return Err ( DispatchError :: Other ( "Unable to convert u128 to balance for bonded_dhx_current" ) ) ;
1501+ } ,
1502+ Ok ( ref x) => {
1503+ bonded_dhx_current = x;
1504+ }
1505+ }
1506+
1507+ // Update storage. Override the default that may have been set in on_initialize
1508+ <BondedDHXForAccountForDate < T > >:: insert (
1509+ (
1510+ start_of_requested_date_millis. clone ( ) ,
1511+ account_id. clone ( ) ,
1512+ ) ,
1513+ bonded_dhx_current. clone ( ) ,
1514+ ) ;
1515+ log:: info!( "set_bonded_dhx_of_account_for_date - account_id: {:?}" , & account_id) ;
1516+ log:: info!( "set_bonded_dhx_of_account_for_date - bonded_dhx_current: {:?}" , & bonded_dhx_current) ;
1517+
1518+ // Emit an event.
1519+ Self :: deposit_event ( Event :: SetBondedDHXOfAccountForDateStored (
1520+ start_of_requested_date_millis. clone ( ) ,
1521+ bonded_dhx_current. clone ( ) ,
1522+ account_id. clone ( ) ,
1523+ ) ) ;
1524+
1525+ // Return a successful DispatchResultWithPostInfo
1526+ Ok ( bonded_dhx_current_u128. clone ( ) )
1527+ }
15291528 }
15301529}
0 commit comments