[#404] innerring: Wait for deposit in initialization

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-02-25 19:53:30 +03:00 committed by Alex Vanin
parent ddf1ac0f28
commit 8c3864e6d6
3 changed files with 72 additions and 1 deletions

View file

@ -46,12 +46,16 @@ const (
defaultNotaryRoundTime = 100
defaultNotaryFallbackTime = 40
innerRingListMethod = "innerRingList"
innerRingListMethod = "innerRingList"
notaryBalanceOfMethod = "balanceOf"
notaryBalanceErrMsg = "can't fetch notary balance"
)
var (
errNotaryNotEnabled = errors.New("notary support was not enabled on this client")
errInvalidIR = errors.New("invalid inner ring list from netmap contract")
errUnexpectedItems = errors.New("invalid number of NEO VM arguments on stack")
)
func defaultNotaryConfig() *notaryCfg {
@ -126,6 +130,32 @@ func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) error {
return nil
}
// GetNotaryDeposit returns deposit of client's account in notary contract.
// Notary support should be enabled in client to use this function.
func (c *Client) GetNotaryDeposit() (int64, error) {
if c.notary == nil {
return 0, errNotaryNotEnabled
}
sh := c.acc.PrivateKey().PublicKey().GetScriptHash()
items, err := c.TestInvoke(c.notary.notary, notaryBalanceOfMethod, sh)
if err != nil {
return 0, errors.Wrap(err, notaryBalanceErrMsg)
}
if len(items) != 1 {
return 0, errors.Wrap(errUnexpectedItems, notaryBalanceErrMsg)
}
bigIntDeposit, err := items[0].TryInteger()
if err != nil {
return 0, errors.Wrap(err, notaryBalanceErrMsg)
}
return bigIntDeposit.Int64(), nil
}
// Invoke invokes contract method by sending tx to notary contract in
// blockchain. Fallback tx is a `RET`. Notary support should be enabled
// in client to use this function.