-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
45 lines (38 loc) · 1.17 KB
/
account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package internal
import (
"strconv"
"github.com/TosinShada/monorepo/clients/horizonclient"
"github.com/TosinShada/monorepo/support/errors"
)
// Account implements the `txnbuild.Account` interface.
type Account struct {
AccountID string
Sequence int64
}
// GetAccountID returns the Account ID.
func (a Account) GetAccountID() string {
return a.AccountID
}
// IncrementSequenceNumber increments the internal record of the
// account's sequence number by 1.
func (a Account) IncrementSequenceNumber() (int64, error) {
a.Sequence++
return a.Sequence, nil
}
func (a Account) GetSequenceNumber() (int64, error) {
return a.Sequence, nil
}
// RefreshSequenceNumber gets an Account's correct in-memory sequence number from Horizon.
func (a *Account) RefreshSequenceNumber(hclient horizonclient.ClientInterface) error {
accountRequest := horizonclient.AccountRequest{AccountID: a.GetAccountID()}
accountDetail, err := hclient.AccountDetail(accountRequest)
if err != nil {
return errors.Wrap(err, "getting account detail")
}
seq, err := strconv.ParseInt(accountDetail.Sequence, 10, 64)
if err != nil {
return errors.Wrap(err, "parsing account seqnum")
}
a.Sequence = seq
return nil
}