@@ -3,6 +3,7 @@ package clightning
3
3
import (
4
4
"crypto/rand"
5
5
"encoding/hex"
6
+ "encoding/json"
6
7
"errors"
7
8
"fmt"
8
9
"math/big"
@@ -13,6 +14,8 @@ import (
13
14
"github.com/elementsproject/peerswap/log"
14
15
"github.com/elementsproject/peerswap/peerswaprpc"
15
16
"github.com/elementsproject/peerswap/premium"
17
+ "google.golang.org/protobuf/encoding/protojson"
18
+ "google.golang.org/protobuf/proto"
16
19
17
20
"github.com/elementsproject/glightning/glightning"
18
21
"github.com/elementsproject/glightning/jrpc2"
@@ -1160,6 +1163,24 @@ func (c *GetPremiumRate) New() interface{} {
1160
1163
}
1161
1164
}
1162
1165
1166
+ type response struct {
1167
+ json.RawMessage
1168
+ }
1169
+
1170
+ // formatProtoMessage formats a proto message to a human readable
1171
+ func formatProtoMessage (m proto.Message ) (response , error ) {
1172
+ mb , err := protojson.MarshalOptions {
1173
+ Multiline : true ,
1174
+ Indent : " " ,
1175
+ AllowPartial : false ,
1176
+ UseProtoNames : true ,
1177
+ UseEnumNumbers : false ,
1178
+ EmitUnpopulated : true ,
1179
+ Resolver : nil ,
1180
+ }.Marshal (m )
1181
+ return response {json .RawMessage (mb )}, err
1182
+ }
1183
+
1163
1184
func (c * GetPremiumRate ) Call () (jrpc2.Result , error ) {
1164
1185
if ! c .cl .isReady {
1165
1186
return nil , ErrWaitingForReady
@@ -1169,11 +1190,11 @@ func (c *GetPremiumRate) Call() (jrpc2.Result, error) {
1169
1190
if err != nil {
1170
1191
return nil , fmt .Errorf ("error getting premium rate: %v" , err )
1171
1192
}
1172
- return & peerswaprpc.PremiumRate {
1193
+ return formatProtoMessage ( & peerswaprpc.PremiumRate {
1173
1194
Asset : peerswaprpc .ToAssetType (e .Asset ()),
1174
1195
Operation : peerswaprpc .ToOperationType (e .Operation ()),
1175
1196
PremiumRatePpm : e .PremiumRatePPM ().Value (),
1176
- }, nil
1197
+ })
1177
1198
}
1178
1199
1179
1200
func (c * GetPremiumRate ) Get (client * ClightningClient ) jrpc2.ServerMethod {
@@ -1221,11 +1242,11 @@ func (c *UpdatePremiumRate) Call() (jrpc2.Result, error) {
1221
1242
if err != nil {
1222
1243
return nil , fmt .Errorf ("error setting premium rate: %v" , err )
1223
1244
}
1224
- return & peerswaprpc.PremiumRate {
1245
+ return formatProtoMessage ( & peerswaprpc.PremiumRate {
1225
1246
Asset : peerswaprpc .ToAssetType (rate .Asset ()),
1226
1247
Operation : peerswaprpc .ToOperationType (rate .Operation ()),
1227
1248
PremiumRatePpm : rate .PremiumRatePPM ().Value (),
1228
- }, nil
1249
+ })
1229
1250
}
1230
1251
1231
1252
func (c * UpdatePremiumRate ) Get (client * ClightningClient ) jrpc2.ServerMethod {
@@ -1268,11 +1289,11 @@ func (c *DeletePremiumRate) Call() (jrpc2.Result, error) {
1268
1289
if err != nil {
1269
1290
return nil , fmt .Errorf ("error deleting premium rate: %v" , err )
1270
1291
}
1271
- return & peerswaprpc.PremiumRate {
1292
+ return formatProtoMessage ( & peerswaprpc.PremiumRate {
1272
1293
Asset : peerswaprpc .ToAssetType (toPremiumAssetType (c .Asset )),
1273
1294
Operation : peerswaprpc .ToOperationType (toPremiumOperationType (c .Operation )),
1274
1295
PremiumRatePpm : 0 ,
1275
- }, nil
1296
+ })
1276
1297
}
1277
1298
1278
1299
func (c * DeletePremiumRate ) Get (client * ClightningClient ) jrpc2.ServerMethod {
@@ -1319,11 +1340,11 @@ func (c *UpdateGlobalPremiumRate) Call() (jrpc2.Result, error) {
1319
1340
if err != nil {
1320
1341
return nil , fmt .Errorf ("error setting default premium rate: %v" , err )
1321
1342
}
1322
- return & peerswaprpc.PremiumRate {
1343
+ return formatProtoMessage ( & peerswaprpc.PremiumRate {
1323
1344
Asset : peerswaprpc .ToAssetType (rate .Asset ()),
1324
1345
Operation : peerswaprpc .ToOperationType (rate .Operation ()),
1325
1346
PremiumRatePpm : rate .PremiumRatePPM ().Value (),
1326
- }, nil
1347
+ })
1327
1348
}
1328
1349
1329
1350
func (c * UpdateGlobalPremiumRate ) Get (client * ClightningClient ) jrpc2.ServerMethod {
@@ -1365,11 +1386,11 @@ func (c *GetGlobalPremiumRate) Call() (jrpc2.Result, error) {
1365
1386
if err != nil {
1366
1387
return nil , fmt .Errorf ("error getting default premium rate: %v" , err )
1367
1388
}
1368
- return & peerswaprpc.PremiumRate {
1389
+ return formatProtoMessage ( & peerswaprpc.PremiumRate {
1369
1390
Asset : peerswaprpc .ToAssetType (rate .Asset ()),
1370
1391
Operation : peerswaprpc .ToOperationType (rate .Operation ()),
1371
1392
PremiumRatePpm : rate .PremiumRatePPM ().Value (),
1372
- }, nil
1393
+ })
1373
1394
}
1374
1395
1375
1396
func (c * GetGlobalPremiumRate ) Get (client * ClightningClient ) jrpc2.ServerMethod {
0 commit comments