forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inflation.go
50 lines (44 loc) · 1.66 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
47
48
49
50
package txnbuild
import (
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
)
// Inflation represents the Stellar inflation operation. See
// https://www.stellar.org/developers/guides/concepts/list-of-operations.html
type Inflation struct {
SourceAccount string
}
// BuildXDR for Inflation returns a fully configured XDR Operation.
func (inf *Inflation) BuildXDR(withMuxedAccounts bool) (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}
if withMuxedAccounts {
SetOpSourceMuxedAccount(&op, inf.SourceAccount)
} else {
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, withMuxedAccounts bool) error {
if xdrOp.Body.Type != xdr.OperationTypeInflation {
return errors.New("error parsing inflation operation from xdr")
}
inf.SourceAccount = accountFromXDR(xdrOp.SourceAccount, withMuxedAccounts)
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(withMuxedAccounts bool) 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
}