forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 6
/
builder_inflation.go
44 lines (34 loc) · 1.17 KB
/
builder_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
package bridge
import (
b "github.com/stellar/go/build"
shared "github.com/stellar/go/services/internal/bridge-compliance-shared"
"github.com/stellar/go/services/internal/bridge-compliance-shared/http/helpers"
"github.com/stellar/go/txnbuild"
)
// InflationOperationBody represents inflation operation
type InflationOperationBody struct {
Source *string
}
// Build returns a txnbuild.Operation
func (op InflationOperationBody) Build() txnbuild.Operation {
txnOp := txnbuild.Inflation{}
if op.Source != nil {
txnOp.SourceAccount = &txnbuild.SimpleAccount{AccountID: *op.Source}
}
return &txnOp
}
// ToTransactionMutator returns go-stellar-base TransactionMutator
func (op InflationOperationBody) ToTransactionMutator() b.TransactionMutator {
var mutators []interface{}
if op.Source != nil {
mutators = append(mutators, b.SourceAccount{*op.Source})
}
return b.Inflation(mutators...)
}
// Validate validates if operation body is valid.
func (op InflationOperationBody) Validate() error {
if op.Source != nil && !shared.IsValidAccountID(*op.Source) {
return helpers.NewInvalidParameterError("source", "Source must be a public key (starting with `G`).")
}
return nil
}