Improve handling state after charging and linking pub-keys
# limitations under the License.
# ------------------------------------------------------------------------
+import copy
import logging
import hashlib
import abc
@@ -322,16 +323,20 @@ class PubKeyHandler(BasicHandler):
public_key_to_store_address: public_key_information,
}
- charging_state = self._charge_for_storing(context, state, sender_account_address)
+ charging_state = self._charge_for_storing(context=context, address_from=sender_account_address)
+ if charging_state is not None:
state.update(charging_state)
-
sender_account = state.get(sender_account_address)
- self._store_public_key_to_account(
+ sender_account = self._store_public_key_to_account(
public_key_to_store_address=public_key_to_store_address,
public_key_to_store_owner_account=sender_account,
)
+ state.update({
+ sender_account_address: sender_account,
+ })
+
return state
def _store_public_key_for_other(self, context, signer_pubkey, transaction_payload):
@@ -409,17 +414,22 @@ class PubKeyHandler(BasicHandler):
public_key_to_store_address: public_key_information,
}
- charging_state = self._charge_for_storing(context=context, state=state, address_from=payer_for_storing_address)
+ charging_state = self._charge_for_storing(context=context, address_from=payer_for_storing_address)
+ if charging_state is not None:
state.update(charging_state)
- self._store_public_key_to_account(
+ public_key_to_store_owner_account = self._store_public_key_to_account(
public_key_to_store_address=public_key_to_store_address,
public_key_to_store_owner_account=public_key_to_store_owner_account,
)
+ state.update({
+ public_key_to_store_owner_address: public_key_to_store_owner_account,
+ })
+
return state
- def _charge_for_storing(self, context, state, address_from):
+ def _charge_for_storing(self, context, address_from):
"""
Send fixed tokens value from address to zero address.
"""
@@ -430,17 +440,19 @@ class PubKeyHandler(BasicHandler):
context=context, address_from=address_from, address_to=ZERO_ADDRESS,
)
- state.update(transfer_state)
-
- return state
+ return transfer_state
@staticmethod
def _store_public_key_to_account(public_key_to_store_address, public_key_to_store_owner_account):
"""
Store public keys to account.
"""
- if public_key_to_store_address not in public_key_to_store_owner_account.pub_keys:
- public_key_to_store_owner_account.pub_keys.append(public_key_to_store_address)
+ account = copy.deepcopy(public_key_to_store_owner_account)
+
+ if public_key_to_store_address not in account.pub_keys:
+ account.pub_keys.append(public_key_to_store_address)
+
+ return account
@staticmethod
def _revoke_pub_key(context, signer_pubkey, revoke_pub_key_payload):
