forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inflation.go
46 lines (40 loc) · 1.47 KB
/
inflation.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
package txnbuild
import (
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
)
// Inflation represents the Stellar inflation operation. See
// https://developers.stellar.org/docs/start/list-of-operations/
type Inflation struct {
SourceAccount string
}
// BuildXDR for Inflation returns a fully configured XDR Operation.
func (inf *Inflation) BuildXDR() (xdr.Operation, error) {
opType := xdr.OperationTypeInflation
body, err := xdr.NewOperationBody(opType, nil)
if err != nil {
return xdr.Operation{}, errors.Wrap(err, "failed to build XDR OperationBody")
}
op := xdr.Operation{Body: body}
SetOpSourceAccount(&op, inf.SourceAccount)
return op, nil
}
// FromXDR for Inflation initialises the txnbuild struct from the corresponding xdr Operation.
func (inf *Inflation) FromXDR(xdrOp xdr.Operation) error {
if xdrOp.Body.Type != xdr.OperationTypeInflation {
return errors.New("error parsing inflation operation from xdr")
}
inf.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
return nil
}
// Validate for Inflation is just a method that implements the Operation interface. No logic is actually performed
// because the inflation operation does not have any required field. Nil is always returned.
func (inf *Inflation) Validate() error {
// no required fields, return nil.
return nil
}
// GetSourceAccount returns the source account of the operation, or the empty string if not
// set.
func (inf *Inflation) GetSourceAccount() string {
return inf.SourceAccount
}