forked from stellar/go
/
path.go
58 lines (44 loc) · 1015 Bytes
/
path.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
55
56
57
58
package resource
import (
"context"
"github.com/stellar/go/amount"
"github.com/stellar/go/services/horizon/internal/paths"
)
func (this *Path) Populate(ctx context.Context, q paths.Query, p paths.Path) (err error) {
this.DestinationAmount = amount.String(q.DestinationAmount)
cost, err := p.Cost(q.DestinationAmount)
if err != nil {
return
}
this.SourceAmount = amount.String(cost)
err = p.Source().Extract(
&this.SourceAssetType,
&this.SourceAssetCode,
&this.SourceAssetIssuer)
if err != nil {
return
}
err = p.Destination().Extract(
&this.DestinationAssetType,
&this.DestinationAssetCode,
&this.DestinationAssetIssuer)
if err != nil {
return
}
path := p.Path()
this.Path = make([]Asset, len(path))
for i, a := range path {
err = a.Extract(
&this.Path[i].Type,
&this.Path[i].Code,
&this.Path[i].Issuer)
if err != nil {
return
}
}
return
}
// stub implementation to satisfy pageable interface
func (this Path) PagingToken() string {
return ""
}