@@ -830,7 +830,6 @@ pub fn casper_env_balance<S: GlobalStateReader, E: Executor>(
830
830
831
831
pub fn casper_transfer < S : GlobalStateReader + ' static , E : Executor > (
832
832
mut caller : impl Caller < Context = Context < S , E > > ,
833
- entity_kind : u32 ,
834
833
entity_addr_ptr : u32 ,
835
834
entity_addr_len : u32 ,
836
835
amount_ptr : u32 ,
@@ -840,57 +839,39 @@ pub fn casper_transfer<S: GlobalStateReader + 'static, E: Executor>(
840
839
return Ok ( u32_from_host_result ( Err ( HostError :: NotCallable ) ) ) ;
841
840
}
842
841
843
- let entity_kind = match EntityKindTag :: from_u32 ( entity_kind) {
844
- Some ( entity_kind) => entity_kind,
845
- None => {
846
- // Unknown target entity kind; failing to proceed with the transfer
847
- return Ok ( u32_from_host_result ( Err ( HostError :: NotCallable ) ) ) ; // fail
848
- }
849
- } ;
850
-
851
842
let amount: u128 = {
852
843
let mut amount_bytes = [ 0u8 ; 16 ] ;
853
844
caller. memory_read_into ( amount_ptr, & mut amount_bytes) ?;
854
845
u128:: from_le_bytes ( amount_bytes)
855
846
} ;
856
847
857
- let target_entity_addr = match entity_kind {
858
- EntityKindTag :: Account => {
859
- let entity_addr = caller. memory_read ( entity_addr_ptr, entity_addr_len as usize ) ?;
860
- debug_assert_eq ! ( entity_addr. len( ) , 32 ) ;
861
-
862
- // SAFETY: entity_addr is 32 bytes long
863
- let account_hash: AccountHash = AccountHash :: new ( entity_addr. try_into ( ) . unwrap ( ) ) ;
864
-
865
- // Resolve indirection to get to the actual addressable entity
866
- let account_key = Key :: Account ( account_hash) ;
867
- match caller. context_mut ( ) . tracking_copy . read ( & account_key) {
868
- Ok ( Some ( StoredValue :: CLValue ( indirect) ) ) => {
869
- // is it an account?
870
- let addressable_entity_key = indirect. into_t :: < Key > ( ) . expect ( "should be key" ) ;
871
- addressable_entity_key
872
- . into_entity_addr ( )
873
- . expect ( "should be entity addr" )
874
- }
875
- Ok ( Some ( other) ) => panic ! ( "should be cl value but got {other:?}" ) ,
876
- Ok ( None ) => return Ok ( u32_from_host_result ( Err ( HostError :: NotCallable ) ) ) ,
877
- Err ( error) => {
878
- error ! (
879
- ?error,
880
- ?account_key,
881
- "Error while reading from storage; aborting"
882
- ) ;
883
- panic ! ( "Error while reading from storage" )
884
- }
848
+ let target_entity_addr = {
849
+ let entity_addr = caller. memory_read ( entity_addr_ptr, entity_addr_len as usize ) ?;
850
+ debug_assert_eq ! ( entity_addr. len( ) , 32 ) ;
851
+
852
+ // SAFETY: entity_addr is 32 bytes long
853
+ let account_hash: AccountHash = AccountHash :: new ( entity_addr. try_into ( ) . unwrap ( ) ) ;
854
+
855
+ // Resolve indirection to get to the actual addressable entity
856
+ let account_key = Key :: Account ( account_hash) ;
857
+ match caller. context_mut ( ) . tracking_copy . read ( & account_key) {
858
+ Ok ( Some ( StoredValue :: CLValue ( indirect) ) ) => {
859
+ // is it an account?
860
+ let addressable_entity_key = indirect. into_t :: < Key > ( ) . expect ( "should be key" ) ;
861
+ addressable_entity_key
862
+ . into_entity_addr ( )
863
+ . expect ( "should be entity addr" )
864
+ }
865
+ Ok ( Some ( other) ) => panic ! ( "should be cl value but got {other:?}" ) ,
866
+ Ok ( None ) => return Ok ( u32_from_host_result ( Err ( HostError :: NotCallable ) ) ) ,
867
+ Err ( error) => {
868
+ error ! (
869
+ ?error,
870
+ ?account_key,
871
+ "Error while reading from storage; aborting"
872
+ ) ;
873
+ panic ! ( "Error while reading from storage" )
885
874
}
886
- }
887
- EntityKindTag :: Contract => {
888
- let entity_addr = caller. memory_read ( entity_addr_ptr, entity_addr_len as usize ) ?;
889
- debug_assert_eq ! ( entity_addr. len( ) , 32 ) ;
890
-
891
- // SAFETY: entity_addr is 32 bytes long
892
- let entity_addr: HashAddr = entity_addr. try_into ( ) . unwrap ( ) ;
893
- EntityAddr :: SmartContract ( entity_addr)
894
875
}
895
876
} ;
896
877
@@ -918,10 +899,6 @@ pub fn casper_transfer<S: GlobalStateReader + 'static, E: Executor>(
918
899
other => panic ! ( "should be account or addressable entity but got {other:?}" ) ,
919
900
} ;
920
901
921
- let _callee_entity_addr = callee_addressable_entity_key
922
- . into_entity_addr ( )
923
- . expect ( "should be entity addr" ) ;
924
-
925
902
let callee_stored_value = caller
926
903
. context_mut ( )
927
904
. tracking_copy
@@ -933,138 +910,48 @@ pub fn casper_transfer<S: GlobalStateReader + 'static, E: Executor>(
933
910
. expect ( "should be addressable entity" ) ;
934
911
let callee_purse = callee_addressable_entity. main_purse ( ) ;
935
912
936
- match entity_kind {
937
- EntityKindTag :: Account => {
938
- let target_purse = match caller
939
- . context_mut ( )
940
- . tracking_copy
941
- . read ( & Key :: AddressableEntity ( target_entity_addr) )
942
- {
943
- Ok ( Some ( StoredValue :: Account ( account) ) ) => {
944
- panic ! ( "Expected AddressableEntity but got {:?}" , account)
945
- }
946
- Ok ( Some ( StoredValue :: AddressableEntity ( addressable_entity) ) ) => {
947
- addressable_entity. main_purse ( )
948
- }
949
- Ok ( Some ( other_entity) ) => {
950
- panic ! ( "Unexpected entity type: {:?}" , other_entity)
951
- }
952
- Ok ( None ) => {
953
- panic ! ( "Addressable entity not found for key={target_entity_addr:?}" ) ;
954
- }
955
- Err ( error) => {
956
- error ! ( ?error, "Error while reading from storage; aborting" ) ;
957
- panic ! ( "Error while reading from storage; aborting" )
958
- }
959
- } ;
960
- // We don't execute anything as it does not make sense to execute an account as there
961
- // are no entry points.
962
- let transaction_hash = caller. context ( ) . transaction_hash ;
963
- let address_generator = Arc :: clone ( & caller. context ( ) . address_generator ) ;
964
- let args = MintTransferArgs {
965
- source : callee_purse,
966
- target : target_purse,
967
- amount : U512 :: from ( amount) ,
968
- maybe_to : None ,
969
- id : None ,
970
- } ;
971
-
972
- let result = system:: mint_transfer (
973
- & mut caller. context_mut ( ) . tracking_copy ,
974
- transaction_hash,
975
- address_generator,
976
- args,
977
- ) ;
978
-
979
- Ok ( u32_from_host_result ( result) )
913
+ let target_purse = match caller
914
+ . context_mut ( )
915
+ . tracking_copy
916
+ . read ( & Key :: AddressableEntity ( target_entity_addr) )
917
+ {
918
+ Ok ( Some ( StoredValue :: Account ( account) ) ) => {
919
+ panic ! ( "Expected AddressableEntity but got {:?}" , account)
980
920
}
981
- EntityKindTag :: Contract => {
982
- // let callee_purse = callee_stored_value.main_purse();
983
-
984
- let transaction_hash = caller. context ( ) . transaction_hash ;
985
- let _address_generator = Arc :: clone ( & caller. context ( ) . address_generator ) ;
986
-
987
- let tracking_copy = caller. context ( ) . tracking_copy . fork2 ( ) ;
988
-
989
- // Take the gas spent so far and use it as a limit for the new VM.
990
- let gas_limit = caller
991
- . gas_consumed ( )
992
- . try_into_remaining ( )
993
- . expect ( "should be remaining" ) ;
994
-
995
- let address_generator = Arc :: clone ( & caller. context ( ) . address_generator ) ;
996
- let execute_request = ExecuteRequestBuilder :: default ( )
997
- . with_initiator ( caller. context ( ) . initiator )
998
- . with_caller_key ( caller. context ( ) . callee )
999
- // .with_callee_key(Key::AddressableEntity(EntityAddr::new_smart_contract(
1000
- // address,
1001
- // )))
1002
- . with_callee_key ( Key :: AddressableEntity ( target_entity_addr) )
1003
- . with_gas_limit ( gas_limit)
1004
- . with_target ( ExecutionKind :: Stored {
1005
- address : target_entity_addr,
1006
- entry_point : "__casper_fallback" . to_string ( ) ,
1007
- } )
1008
- . with_transferred_value ( amount)
1009
- . with_input ( Bytes :: new ( ) )
1010
- . with_transaction_hash ( transaction_hash)
1011
- // We're using shared address generator there as we need to preserve and advance the
1012
- // state of deterministic address generator across chain of calls.
1013
- . with_shared_address_generator ( address_generator)
1014
- . with_chain_name ( caller. context ( ) . chain_name . clone ( ) )
1015
- . with_block_time ( caller. context ( ) . block_time )
1016
- . build ( )
1017
- . expect ( "should build" ) ;
921
+ Ok ( Some ( StoredValue :: AddressableEntity ( addressable_entity) ) ) => {
922
+ addressable_entity. main_purse ( )
923
+ }
924
+ Ok ( Some ( other_entity) ) => {
925
+ panic ! ( "Unexpected entity type: {:?}" , other_entity)
926
+ }
927
+ Ok ( None ) => {
928
+ panic ! ( "Addressable entity not found for key={target_entity_addr:?}" ) ;
929
+ }
930
+ Err ( error) => {
931
+ error ! ( ?error, "Error while reading from storage; aborting" ) ;
932
+ panic ! ( "Error while reading from storage; aborting" )
933
+ }
934
+ } ;
935
+ // We don't execute anything as it does not make sense to execute an account as there
936
+ // are no entry points.
937
+ let transaction_hash = caller. context ( ) . transaction_hash ;
938
+ let address_generator = Arc :: clone ( & caller. context ( ) . address_generator ) ;
939
+ let args = MintTransferArgs {
940
+ source : callee_purse,
941
+ target : target_purse,
942
+ amount : U512 :: from ( amount) ,
943
+ maybe_to : None ,
944
+ id : None ,
945
+ } ;
1018
946
1019
- match caller
1020
- . context ( )
1021
- . executor
1022
- . execute ( tracking_copy, execute_request)
1023
- {
1024
- Ok ( ExecuteResult {
1025
- host_error,
1026
- output,
1027
- gas_usage,
1028
- effects,
1029
- cache,
1030
- } ) => {
1031
- caller. consume_gas ( gas_usage. gas_spent ( ) ) ;
1032
- let _ = output; // TODO: What to do with the output of a fallback code? Need to emit a message
1033
- // with this
1034
-
1035
- let host_result = match host_error {
1036
- Some ( host_error) => Err ( host_error) ,
1037
- None => {
1038
- caller
1039
- . context_mut ( )
1040
- . tracking_copy
1041
- . apply_changes ( effects, cache) ;
1042
- Ok ( ( ) )
1043
- }
1044
- } ;
1045
-
1046
- let gas_spent = gas_usage
1047
- . gas_limit ( )
1048
- . checked_sub ( gas_usage. remaining_points ( ) )
1049
- . expect ( "remaining points always below or equal to the limit" ) ;
1050
-
1051
- match caller. consume_gas ( gas_spent) {
1052
- MeteringPoints :: Remaining ( _) => { }
1053
- MeteringPoints :: Exhausted => {
1054
- todo ! ( "exhausted" )
1055
- }
1056
- }
947
+ let result = system:: mint_transfer (
948
+ & mut caller. context_mut ( ) . tracking_copy ,
949
+ transaction_hash,
950
+ address_generator,
951
+ args,
952
+ ) ;
1057
953
1058
- Ok ( u32_from_host_result ( host_result) )
1059
- }
1060
- Err ( ExecuteError :: WasmPreparation ( preparation_error) ) => {
1061
- // This is a bug in the EE, as it should have been caught during the preparation
1062
- // phase when the contract was stored in the global state.
1063
- unreachable ! ( "Preparation error: {:?}" , preparation_error)
1064
- }
1065
- }
1066
- }
1067
- }
954
+ Ok ( u32_from_host_result ( result) )
1068
955
}
1069
956
1070
957
pub fn casper_upgrade < S : GlobalStateReader + ' static , E : Executor > (
0 commit comments