-
Notifications
You must be signed in to change notification settings - Fork 501
/
bump_sequence.go
54 lines (47 loc) · 1.64 KB
/
bump_sequence.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
46
47
48
49
50
51
52
53
54
package txnbuild
import (
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
)
// BumpSequence represents the Stellar bump sequence operation. See
// https://developers.stellar.org/docs/start/list-of-operations/
type BumpSequence struct {
BumpTo int64
SourceAccount string
}
// BuildXDR for BumpSequence returns a fully configured XDR Operation.
func (bs *BumpSequence) BuildXDR() (xdr.Operation, error) {
opType := xdr.OperationTypeBumpSequence
xdrOp := xdr.BumpSequenceOp{BumpTo: xdr.SequenceNumber(bs.BumpTo)}
body, err := xdr.NewOperationBody(opType, xdrOp)
if err != nil {
return xdr.Operation{}, errors.Wrap(err, "failed to build XDR OperationBody")
}
op := xdr.Operation{Body: body}
SetOpSourceAccount(&op, bs.SourceAccount)
return op, nil
}
// FromXDR for BumpSequence initialises the txnbuild struct from the corresponding xdr Operation.
func (bs *BumpSequence) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetBumpSequenceOp()
if !ok {
return errors.New("error parsing bump_sequence operation from xdr")
}
bs.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
bs.BumpTo = int64(result.BumpTo)
return nil
}
// Validate for BumpSequence validates the required struct fields. It returns an error if any of the fields are
// invalid. Otherwise, it returns nil.
func (bs *BumpSequence) Validate() error {
err := validateAmount(bs.BumpTo)
if err != nil {
return NewValidationError("BumpTo", err.Error())
}
return nil
}
// GetSourceAccount returns the source account of the operation, or the empty string if not
// set.
func (bs *BumpSequence) GetSourceAccount() string {
return bs.SourceAccount
}