From 5ac95784355283a2f7eeacb6acd3fc5948ac32d5 Mon Sep 17 00:00:00 2001 From: aarifullin Date: Tue, 23 Jan 2024 18:30:54 +0300 Subject: [PATCH] [#45] morph: Pass actor providers instead actors themselves * Make NewContractStorage and NewContractStorageWithSimpleActor recieve actor providers instead actors themselves because actors may be expired if websocket connection was broken. Signed-off-by: Airat Arifullin --- pkg/morph/policy/policy_contract_storage.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/morph/policy/policy_contract_storage.go b/pkg/morph/policy/policy_contract_storage.go index 2e0a756..45220a3 100644 --- a/pkg/morph/policy/policy_contract_storage.go +++ b/pkg/morph/policy/policy_contract_storage.go @@ -29,18 +29,28 @@ type ContractStorage struct { var _ engine.MorphRuleChainStorage = (*ContractStorage)(nil) -func NewContractStorage(actor client.Actor, contract util.Uint160) *ContractStorage { +type ActorProvider interface { + GetActor() client.Actor +} + +func NewContractStorage(actorProvider ActorProvider, contract util.Uint160) *ContractStorage { return &ContractStorage{ - contractInterface: client.New(actor, contract), + contractInterface: client.New(actorProvider.GetActor(), contract), } } -func NewContractStorageWithSimpleActor(rpcActor actor.RPCActor, acc *wallet.Account, contract util.Uint160) (*ContractStorage, error) { - act, err := actor.NewSimple(rpcActor, acc) +type RPCActorProvider interface { + GetRPCActor() actor.RPCActor +} + +func NewContractStorageWithSimpleActor(rpcActorProvider RPCActorProvider, acc *wallet.Account, contract util.Uint160) (*ContractStorage, error) { + act, err := actor.NewSimple(rpcActorProvider.GetRPCActor(), acc) if err != nil { return nil, fmt.Errorf("failed to create simple actor: %w", err) } - return NewContractStorage(act, contract), nil + return &ContractStorage{ + contractInterface: client.New(act, contract), + }, nil } func (s *ContractStorage) AddMorphRuleChain(name chain.Name, target engine.Target, c *chain.Chain) (txHash util.Uint256, vub uint32, err error) { -- 2.45.2