[#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 <aarifullin@yadro.com>
This commit is contained in:
aarifullin 2024-01-23 18:30:54 +03:00
parent 06cbfe8691
commit 5ac9578435

View file

@ -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) {