[#63] frostfsid/client: Support proxy

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2023-12-15 17:04:54 +03:00
parent 23e85d11c4
commit bce7ef18c8
2 changed files with 26 additions and 5 deletions

View file

@ -6,9 +6,11 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-contract/commonclient" "git.frostfs.info/TrueCloudLab/frostfs-contract/commonclient"
"github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result" "github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor" "github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/notary"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
@ -24,7 +26,7 @@ type (
} }
Options struct { Options struct {
// todo add proxy params ProxyContract util.Uint160
} }
) )
@ -122,9 +124,28 @@ const (
deleteGroupMethod = "deleteGroup" deleteGroupMethod = "deleteGroup"
) )
// New creates a new Client. Options can be nil. // New creates a new Client. Options can be empty.
func New(ra actor.RPCActor, acc *wallet.Account, contract util.Uint160, _ *Options) (*Client, error) { func New(ra actor.RPCActor, acc *wallet.Account, contract util.Uint160, opt Options) (*Client, error) {
act, err := actor.NewSimple(ra, acc) signers := []actor.SignerAccount{{
Signer: transaction.Signer{
Account: acc.Contract.ScriptHash(),
Scopes: transaction.CalledByEntry,
},
Account: acc,
}}
if !opt.ProxyContract.Equals(util.Uint160{}) {
signers = append([]actor.SignerAccount{{
Signer: transaction.Signer{
Account: opt.ProxyContract,
Scopes: transaction.CustomContracts,
AllowedContracts: []util.Uint160{contract},
},
Account: notary.FakeContractAccount(opt.ProxyContract),
}}, signers...)
}
act, err := actor.New(ra, signers)
if err != nil { if err != nil {
return nil, fmt.Errorf("init actor: %w", err) return nil, fmt.Errorf("init actor: %w", err)
} }

View file

@ -63,7 +63,7 @@ func frostfsidRPCClient(t *testing.T, address string, contractHash util.Uint160,
acc = accs[0] acc = accs[0]
} }
cli, err := client.New(rpcCli, acc, contractHash, nil) cli, err := client.New(rpcCli, acc, contractHash, client.Options{})
require.NoError(t, err) require.NoError(t, err)
return cli, rpcCli return cli, rpcCli