forked from TrueCloudLab/frostfs-node
[#496] morph/client: provide notary options on client creation
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
7cf0093012
commit
458fc4f5ae
5 changed files with 68 additions and 46 deletions
|
@ -31,6 +31,8 @@ type (
|
|||
}
|
||||
|
||||
notaryCfg struct {
|
||||
proxy util.Uint160
|
||||
|
||||
txValidTime, roundTime, fallbackTime uint32
|
||||
|
||||
alphabetSource AlphabetKeys
|
||||
|
@ -63,10 +65,10 @@ func defaultNotaryConfig(c *Client) *notaryCfg {
|
|||
}
|
||||
}
|
||||
|
||||
// EnableNotarySupport creates notary structure in client that provides
|
||||
// enableNotarySupport creates notary structure in client that provides
|
||||
// ability for client to get alphabet keys from committee or provided source
|
||||
// and use proxy contract script hash to create tx for notary contract.
|
||||
func (c *Client) EnableNotarySupport(proxy util.Uint160, opts ...NotaryOption) error {
|
||||
func (c *Client) enableNotarySupport(opts ...NotaryOption) error {
|
||||
cfg := defaultNotaryConfig(c)
|
||||
|
||||
for _, opt := range opts {
|
||||
|
@ -78,9 +80,13 @@ func (c *Client) EnableNotarySupport(proxy util.Uint160, opts ...NotaryOption) e
|
|||
return fmt.Errorf("can't get notary contract script hash: %w", err)
|
||||
}
|
||||
|
||||
if cfg.proxy.Equals(util.Uint160{}) {
|
||||
return errors.New("proxy contract hash is missing")
|
||||
}
|
||||
|
||||
c.notary = ¬ary{
|
||||
notary: notaryContract,
|
||||
proxy: proxy,
|
||||
proxy: cfg.proxy,
|
||||
txValidTime: cfg.txValidTime,
|
||||
roundTime: cfg.roundTime,
|
||||
fallbackTime: cfg.fallbackTime,
|
||||
|
@ -91,7 +97,7 @@ func (c *Client) EnableNotarySupport(proxy util.Uint160, opts ...NotaryOption) e
|
|||
}
|
||||
|
||||
// NotaryEnabled returns true if notary support was enabled in this instance
|
||||
// of client by calling `EnableNotarySupport()`. Otherwise returns false.
|
||||
// of client by providing notary options on client creation. Otherwise returns false.
|
||||
func (c *Client) NotaryEnabled() bool {
|
||||
return c.notary != nil
|
||||
}
|
||||
|
@ -102,8 +108,7 @@ func (c *Client) NotaryEnabled() bool {
|
|||
// be called periodically. Notary support should be enabled in client to
|
||||
// use this function.
|
||||
//
|
||||
// This function must be invoked after `EnableNotarySupport()` otherwise it
|
||||
// throws panic.
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (util.Uint256, error) {
|
||||
if c.notary == nil {
|
||||
panic(notaryNotEnabledPanicMsg)
|
||||
|
@ -138,8 +143,7 @@ func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (util.Uint256
|
|||
// GetNotaryDeposit returns deposit of client's account in notary contract.
|
||||
// Notary support should be enabled in client to use this function.
|
||||
//
|
||||
// This function must be invoked after `EnableNotarySupport()` otherwise it
|
||||
// throws panic.
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
func (c *Client) GetNotaryDeposit() (int64, error) {
|
||||
if c.notary == nil {
|
||||
panic(notaryNotEnabledPanicMsg)
|
||||
|
@ -167,8 +171,7 @@ func (c *Client) GetNotaryDeposit() (int64, error) {
|
|||
// UpdateNotaryList updates list of notary nodes in designate contract. Requires
|
||||
// committee multi signature.
|
||||
//
|
||||
// This function must be invoked after `EnableNotarySupport()` otherwise it
|
||||
// throws panic.
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
func (c *Client) UpdateNotaryList(list keys.PublicKeys) error {
|
||||
if c.notary == nil {
|
||||
panic(notaryNotEnabledPanicMsg)
|
||||
|
@ -185,8 +188,7 @@ func (c *Client) UpdateNotaryList(list keys.PublicKeys) error {
|
|||
// As for side chain list should contain all inner ring nodes.
|
||||
// Requires committee multi signature.
|
||||
//
|
||||
// This function must be invoked after `EnableNotarySupport()` otherwise it
|
||||
// throws panic.
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
func (c *Client) UpdateNeoFSAlphabetList(list keys.PublicKeys) error {
|
||||
if c.notary == nil {
|
||||
panic(notaryNotEnabledPanicMsg)
|
||||
|
@ -203,8 +205,7 @@ func (c *Client) UpdateNeoFSAlphabetList(list keys.PublicKeys) error {
|
|||
// blockchain. Fallback tx is a `RET`. If Notary support is not enabled
|
||||
// it fallbacks to a simple `Invoke()`.
|
||||
//
|
||||
// This function must be invoked after `EnableNotarySupport()` otherwise it
|
||||
// throws panic.
|
||||
// This function must be invoked with notary enabled otherwise it throws panic.
|
||||
func (c *Client) NotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, method string, args ...interface{}) error {
|
||||
if c.notary == nil {
|
||||
return c.Invoke(contract, fee, method, args...)
|
||||
|
@ -497,6 +498,13 @@ func WithAlphabetSource(t AlphabetKeys) NotaryOption {
|
|||
}
|
||||
}
|
||||
|
||||
// WithProxyContract sets proxy contract hash.
|
||||
func WithProxyContract(h util.Uint160) NotaryOption {
|
||||
return func(c *notaryCfg) {
|
||||
c.proxy = h
|
||||
}
|
||||
}
|
||||
|
||||
const alreadyOnChainErrorMessage = "already on chain"
|
||||
|
||||
// Neo RPC node can return `core.ErrInvalidAttribute` error with
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue