@@ -34,6 +34,16 @@ import (
34
34
const (
35
35
// serviceListenAddress is the listening address of the service.
36
36
serviceListenAddress = "localhost:8095"
37
+
38
+ // supportedAssetIdStr is the hex-encoded asset ID for which this price
39
+ // oracle provides exchange rates.
40
+ supportedAssetIdStr = "7b4336d33b019df9438e586f83c587ca00fa6560249" +
41
+ "7b93ace193e9ce53b1a67"
42
+
43
+ // supportedGroupKeyStr is the hex-encoded asset group key for which
44
+ // this price oracle provides exchange rates.
45
+ supportedGroupKeyStr = "02875ce409b587a6656357639d099ad9eb08396d0d" +
46
+ "fea8930a45e742c81d6fc782"
37
47
)
38
48
39
49
// setupLogger sets up the logger to write logs to a file.
@@ -65,42 +75,86 @@ type RpcPriceOracleServer struct {
65
75
oraclerpc.UnimplementedPriceOracleServer
66
76
}
67
77
68
- // isSupportedSubjectAsset returns true if the given subject asset is supported
69
- // by the price oracle, and false otherwise.
70
- func isSupportedSubjectAsset ( subjectAsset * oraclerpc.AssetSpecifier ) bool {
78
+ // isSupportedAssetID returns true if the given asset ID is supported by the
79
+ // price oracle, and false otherwise.
80
+ func isSupportedAssetID ( rpcAssetSpec * oraclerpc.AssetSpecifier ) bool {
71
81
// Ensure that the subject asset is set.
72
- if subjectAsset == nil {
82
+ if rpcAssetSpec == nil {
73
83
logrus .Info ("Subject asset is not set (nil)" )
74
84
return false
75
85
}
76
86
77
- supportedAssetIdStr := "7b4336d33b019df9438e586f83c587ca00fa65602497b9" +
78
- "3ace193e9ce53b1a67"
79
87
supportedAssetIdBytes , err := hex .DecodeString (supportedAssetIdStr )
80
88
if err != nil {
81
89
fmt .Println ("Error decoding supported asset hex string:" , err )
82
90
return false
83
91
}
84
92
85
93
// Check the subject asset bytes if set.
86
- subjectAssetIdBytes := subjectAsset .GetAssetId ()
94
+ subjectAssetIdBytes := rpcAssetSpec .GetAssetId ()
87
95
if len (subjectAssetIdBytes ) > 0 {
88
96
logrus .Infof ("Subject asset ID bytes populated: %x" ,
89
97
supportedAssetIdBytes )
90
98
return bytes .Equal (supportedAssetIdBytes , subjectAssetIdBytes )
91
99
}
92
100
93
- subjectAssetIdStr := subjectAsset .GetAssetIdStr ()
101
+ subjectAssetIdStr := rpcAssetSpec .GetAssetIdStr ()
94
102
if len (subjectAssetIdStr ) > 0 {
95
103
logrus .Infof ("Subject asset ID str populated: %s" ,
96
104
supportedAssetIdStr )
97
105
return subjectAssetIdStr == supportedAssetIdStr
98
106
}
99
107
100
108
logrus .Infof ("Subject asset ID not set" )
109
+
110
+ return false
111
+ }
112
+
113
+ // isSupportedAssetGroupKey returns true if the given asset group key is
114
+ // supported by the price oracle, and false otherwise.
115
+ func isSupportedAssetGroupKey (
116
+ rpcAssetSpec * oraclerpc.AssetSpecifier ) bool {
117
+
118
+ // Ensure that the subject asset is not nil.
119
+ if rpcAssetSpec == nil {
120
+ logrus .Info ("Subject asset is not set (nil)" )
121
+ return false
122
+ }
123
+
124
+ supportedGroupKeyBytes , err := hex .DecodeString (supportedGroupKeyStr )
125
+ if err != nil {
126
+ fmt .Println ("Error decoding supported asset group key hex " +
127
+ "string:" , err )
128
+ return false
129
+ }
130
+
131
+ // Check the subject asset group key bytes if set.
132
+ subjectGroupKeyBytes := rpcAssetSpec .GetGroupKey ()
133
+ if len (subjectGroupKeyBytes ) > 0 {
134
+ logrus .Infof ("Subject asset group key bytes populated: %x" ,
135
+ supportedGroupKeyBytes )
136
+ return bytes .Equal (supportedGroupKeyBytes , subjectGroupKeyBytes )
137
+ }
138
+
139
+ subjectGroupKeyStr := rpcAssetSpec .GetGroupKeyStr ()
140
+ if len (subjectGroupKeyStr ) > 0 {
141
+ logrus .Infof ("Subject asset group key str populated: %s" ,
142
+ supportedGroupKeyStr )
143
+ return subjectGroupKeyStr == supportedGroupKeyStr
144
+ }
145
+
146
+ logrus .Infof ("Subject asset group key not set" )
147
+
101
148
return false
102
149
}
103
150
151
+ // isSupportedAssetID returns true if the given subject asset is
152
+ // supported by the price oracle, and false otherwise.
153
+ func isSupportedSubjectAsset (subjectAsset * oraclerpc.AssetSpecifier ) bool {
154
+ return isSupportedAssetID (subjectAsset ) ||
155
+ isSupportedAssetGroupKey (subjectAsset )
156
+ }
157
+
104
158
// getPurchaseRate returns the buy (purchase) rate for the asset. The unit of
105
159
// the rate is the number of TAP asset units per BTC.
106
160
//
@@ -265,7 +319,7 @@ func (p *RpcPriceOracleServer) QueryAssetRates(_ context.Context,
265
319
266
320
// Ensure that the subject asset is supported.
267
321
if ! isSupportedSubjectAsset (req .SubjectAsset ) {
268
- logrus .Infof ("Unsupported subject asset ID str : %v\n " ,
322
+ logrus .Infof ("Unsupported subject asset: %v\n " ,
269
323
req .SubjectAsset )
270
324
271
325
return & oraclerpc.QueryAssetRatesResponse {
0 commit comments