[#45] morph: Pass actor providers instead actors themselves
All checks were successful
DCO action / DCO (pull_request) Successful in 58s
Tests and linters / Tests (1.21) (pull_request) Successful in 1m3s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m12s
Tests and linters / Staticcheck (pull_request) Successful in 1m27s
Tests and linters / Tests with -race (pull_request) Successful in 1m35s
Tests and linters / Lint (pull_request) Successful in 2m7s

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