[#1558] morph/client: Reuse notary rpcclient wrapper
All checks were successful
DCO action / DCO (pull_request) Successful in 5m31s
Tests and linters / Run gofumpt (pull_request) Successful in 5m35s
Tests and linters / gopls check (pull_request) Successful in 6m9s
Pre-commit hooks / Pre-commit (pull_request) Successful in 6m25s
Tests and linters / Staticcheck (pull_request) Successful in 6m26s
Build / Build Components (pull_request) Successful in 7m19s
Vulncheck / Vulncheck (pull_request) Successful in 7m16s
Tests and linters / Tests (pull_request) Successful in 7m37s
Tests and linters / Tests with -race (pull_request) Successful in 7m56s
Tests and linters / Lint (pull_request) Successful in 8m44s
Tests and linters / Run gofumpt (push) Successful in 1m32s
Vulncheck / Vulncheck (push) Successful in 3m2s
Tests and linters / Staticcheck (push) Successful in 3m43s
Build / Build Components (push) Successful in 4m5s
Tests and linters / Lint (push) Successful in 4m29s
Pre-commit hooks / Pre-commit (push) Successful in 5m7s
Tests and linters / Tests (push) Successful in 5m16s
Tests and linters / Tests with -race (push) Successful in 5m29s
Tests and linters / gopls check (push) Successful in 5m37s
All checks were successful
DCO action / DCO (pull_request) Successful in 5m31s
Tests and linters / Run gofumpt (pull_request) Successful in 5m35s
Tests and linters / gopls check (pull_request) Successful in 6m9s
Pre-commit hooks / Pre-commit (pull_request) Successful in 6m25s
Tests and linters / Staticcheck (pull_request) Successful in 6m26s
Build / Build Components (pull_request) Successful in 7m19s
Vulncheck / Vulncheck (pull_request) Successful in 7m16s
Tests and linters / Tests (pull_request) Successful in 7m37s
Tests and linters / Tests with -race (pull_request) Successful in 7m56s
Tests and linters / Lint (pull_request) Successful in 8m44s
Tests and linters / Run gofumpt (push) Successful in 1m32s
Vulncheck / Vulncheck (push) Successful in 3m2s
Tests and linters / Staticcheck (push) Successful in 3m43s
Build / Build Components (push) Successful in 4m5s
Tests and linters / Lint (push) Successful in 4m29s
Pre-commit hooks / Pre-commit (push) Successful in 5m7s
Tests and linters / Tests (push) Successful in 5m16s
Tests and linters / Tests with -race (push) Successful in 5m29s
Tests and linters / gopls check (push) Successful in 5m37s
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
|
||||
defaultNotaryRoundTime = 100
|
||||
|
||||
notaryBalanceOfMethod = "balanceOf"
|
||||
notaryExpirationOfMethod = "expirationOf"
|
||||
setDesignateMethod = "designateAsRole"
|
||||
|
||||
notaryBalanceErrMsg = "fetch notary balance"
|
||||
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 {
|
||||
return ¬aryCfg{
|
||||
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)
|
||||
}
|
||||
|
||||
currentTill, err := c.depositExpirationOf()
|
||||
r := notary.NewReader(c.rpcActor)
|
||||
currentTill, err := r.ExpirationOf(c.acc.PrivateKey().GetScriptHash())
|
||||
if err != nil {
|
||||
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)
|
||||
return res, err
|
||||
}
|
||||
|
@ -237,18 +233,10 @@ func (c *Client) GetNotaryDeposit() (res int64, err error) {
|
|||
|
||||
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 {
|
||||
return 0, fmt.Errorf("test invoke (%s): %w", notaryBalanceOfMethod, 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 0, fmt.Errorf("get notary deposit: %w", err)
|
||||
}
|
||||
|
||||
return bigIntDeposit.Int64(), nil
|
||||
|
@ -651,24 +639,6 @@ func (c *Client) notaryTxValidationLimit() (uint32, error) {
|
|||
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.
|
||||
// For FrostFS Alphabet M is a 2/3+1 of it (like in dBFT).
|
||||
// If committee is true, returns M as N/2+1.
|
||||
|
|
Loading…
Reference in a new issue