forked from TrueCloudLab/frostfs-node
[#1558] morph/client: Reuse notary rpcclient wrapper
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
7151c71d51
commit
d165ac042c
1 changed files with 7 additions and 37 deletions
|
@ -58,16 +58,11 @@ const (
|
||||||
defaultNotaryValidTime = 50
|
defaultNotaryValidTime = 50
|
||||||
defaultNotaryRoundTime = 100
|
defaultNotaryRoundTime = 100
|
||||||
|
|
||||||
notaryBalanceOfMethod = "balanceOf"
|
|
||||||
notaryExpirationOfMethod = "expirationOf"
|
|
||||||
setDesignateMethod = "designateAsRole"
|
setDesignateMethod = "designateAsRole"
|
||||||
|
|
||||||
notaryBalanceErrMsg = "fetch notary balance"
|
|
||||||
notaryNotEnabledPanicMsg = "notary support was not enabled on this client"
|
notaryNotEnabledPanicMsg = "notary support was not enabled on this client"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errUnexpectedItems = errors.New("invalid number of NEO VM arguments on stack")
|
|
||||||
|
|
||||||
func defaultNotaryConfig(c *Client) *notaryCfg {
|
func defaultNotaryConfig(c *Client) *notaryCfg {
|
||||||
return ¬aryCfg{
|
return ¬aryCfg{
|
||||||
txValidTime: defaultNotaryValidTime,
|
txValidTime: defaultNotaryValidTime,
|
||||||
|
@ -158,12 +153,13 @@ func (c *Client) DepositNotary(ctx context.Context, amount fixedn.Fixed8, delta
|
||||||
return util.Uint256{}, fmt.Errorf("get blockchain height: %w", err)
|
return util.Uint256{}, fmt.Errorf("get blockchain height: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTill, err := c.depositExpirationOf()
|
r := notary.NewReader(c.rpcActor)
|
||||||
|
currentTill, err := r.ExpirationOf(c.acc.PrivateKey().GetScriptHash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.Uint256{}, fmt.Errorf("get previous expiration value: %w", err)
|
return util.Uint256{}, fmt.Errorf("get previous expiration value: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
till := max(int64(bc+delta), currentTill)
|
till := max(int64(bc+delta), int64(currentTill))
|
||||||
res, _, err := c.depositNotary(ctx, amount, till)
|
res, _, err := c.depositNotary(ctx, amount, till)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -237,18 +233,10 @@ func (c *Client) GetNotaryDeposit() (res int64, err error) {
|
||||||
|
|
||||||
sh := c.acc.PrivateKey().PublicKey().GetScriptHash()
|
sh := c.acc.PrivateKey().PublicKey().GetScriptHash()
|
||||||
|
|
||||||
items, err := c.TestInvoke(c.notary.notary, notaryBalanceOfMethod, sh)
|
r := notary.NewReader(c.rpcActor)
|
||||||
|
bigIntDeposit, err := r.BalanceOf(sh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("test invoke (%s): %w", notaryBalanceOfMethod, err)
|
return 0, fmt.Errorf("get notary deposit: %w", err)
|
||||||
}
|
|
||||||
|
|
||||||
if len(items) != 1 {
|
|
||||||
return 0, wrapFrostFSError(fmt.Errorf("%v: %w", notaryBalanceErrMsg, errUnexpectedItems))
|
|
||||||
}
|
|
||||||
|
|
||||||
bigIntDeposit, err := items[0].TryInteger()
|
|
||||||
if err != nil {
|
|
||||||
return 0, wrapFrostFSError(fmt.Errorf("%v: %w", notaryBalanceErrMsg, err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bigIntDeposit.Int64(), nil
|
return bigIntDeposit.Int64(), nil
|
||||||
|
@ -651,24 +639,6 @@ func (c *Client) notaryTxValidationLimit() (uint32, error) {
|
||||||
return rounded, nil
|
return rounded, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) depositExpirationOf() (int64, error) {
|
|
||||||
expirationRes, err := c.TestInvoke(c.notary.notary, notaryExpirationOfMethod, c.acc.PrivateKey().GetScriptHash())
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("test invoke (%s): %w", notaryExpirationOfMethod, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(expirationRes) != 1 {
|
|
||||||
return 0, fmt.Errorf("method returned unexpected item count: %d", len(expirationRes))
|
|
||||||
}
|
|
||||||
|
|
||||||
currentTillBig, err := expirationRes[0].TryInteger()
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("parse deposit till value: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentTillBig.Int64(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// sigCount returns the number of required signature.
|
// sigCount returns the number of required signature.
|
||||||
// For FrostFS Alphabet M is a 2/3+1 of it (like in dBFT).
|
// For FrostFS Alphabet M is a 2/3+1 of it (like in dBFT).
|
||||||
// If committee is true, returns M as N/2+1.
|
// If committee is true, returns M as N/2+1.
|
||||||
|
|
Loading…
Reference in a new issue