forked from TrueCloudLab/frostfs-node
[#751] morph/client: Add custom signer scope support
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
f121a73049
commit
43dfccd9b3
3 changed files with 31 additions and 4 deletions
|
@ -41,6 +41,8 @@ type Client struct {
|
||||||
|
|
||||||
waitInterval time.Duration
|
waitInterval time.Duration
|
||||||
|
|
||||||
|
signer *transaction.Signer
|
||||||
|
|
||||||
notary *notary
|
notary *notary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +85,10 @@ func (c *Client) Invoke(contract util.Uint160, fee fixedn.Fixed8, method string,
|
||||||
|
|
||||||
cosigner := []transaction.Signer{
|
cosigner := []transaction.Signer{
|
||||||
{
|
{
|
||||||
Account: c.acc.PrivateKey().PublicKey().GetScriptHash(),
|
Account: c.acc.PrivateKey().PublicKey().GetScriptHash(),
|
||||||
Scopes: transaction.Global,
|
Scopes: c.signer.Scopes,
|
||||||
|
AllowedContracts: c.signer.AllowedContracts,
|
||||||
|
AllowedGroups: c.signer.AllowedGroups,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
|
"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/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -27,6 +28,8 @@ type cfg struct {
|
||||||
gas util.Uint160 // native gas script-hash
|
gas util.Uint160 // native gas script-hash
|
||||||
|
|
||||||
waitInterval time.Duration
|
waitInterval time.Duration
|
||||||
|
|
||||||
|
signer *transaction.Signer
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -40,6 +43,9 @@ func defaultConfig() *cfg {
|
||||||
dialTimeout: defaultDialTimeout,
|
dialTimeout: defaultDialTimeout,
|
||||||
logger: zap.L(),
|
logger: zap.L(),
|
||||||
waitInterval: defaultWaitInterval,
|
waitInterval: defaultWaitInterval,
|
||||||
|
signer: &transaction.Signer{
|
||||||
|
Scopes: transaction.Global,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +108,7 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error)
|
||||||
gas: gas,
|
gas: gas,
|
||||||
designate: designate,
|
designate: designate,
|
||||||
waitInterval: cfg.waitInterval,
|
waitInterval: cfg.waitInterval,
|
||||||
|
signer: cfg.signer,
|
||||||
}
|
}
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
|
@ -148,3 +155,17 @@ func WithLogger(logger *logger.Logger) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithSigner returns a client constructor option
|
||||||
|
// that specifies the signer and the scope of the transaction.
|
||||||
|
//
|
||||||
|
// Ignores nil value.
|
||||||
|
//
|
||||||
|
// If option not provided, signer with global scope is used.
|
||||||
|
func WithSigner(signer *transaction.Signer) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
if signer != nil {
|
||||||
|
c.signer = signer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -342,8 +342,10 @@ func (c *Client) notaryCosigners(ir []*keys.PublicKey, committee bool) ([]transa
|
||||||
}
|
}
|
||||||
|
|
||||||
s = append(s, transaction.Signer{
|
s = append(s, transaction.Signer{
|
||||||
Account: hash.Hash160(multisigScript),
|
Account: hash.Hash160(multisigScript),
|
||||||
Scopes: transaction.Global,
|
Scopes: c.signer.Scopes,
|
||||||
|
AllowedContracts: c.signer.AllowedContracts,
|
||||||
|
AllowedGroups: c.signer.AllowedGroups,
|
||||||
})
|
})
|
||||||
|
|
||||||
// last one is a placeholder for notary contract signature
|
// last one is a placeholder for notary contract signature
|
||||||
|
|
Loading…
Reference in a new issue