Skip to content

Commit e63ea8e

Browse files
committed
Revert "Merge branch 'premium' into testnet4"
This reverts commit 4823d64, reversing changes made to 74666b6.
1 parent 4823d64 commit e63ea8e

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

clightning/clightning_commands.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package clightning
33
import (
44
"crypto/rand"
55
"encoding/hex"
6+
"encoding/json"
67
"errors"
78
"fmt"
89
"math/big"
@@ -13,6 +14,8 @@ import (
1314
"github.com/elementsproject/peerswap/log"
1415
"github.com/elementsproject/peerswap/peerswaprpc"
1516
"github.com/elementsproject/peerswap/premium"
17+
"google.golang.org/protobuf/encoding/protojson"
18+
"google.golang.org/protobuf/proto"
1619

1720
"github.com/elementsproject/glightning/glightning"
1821
"github.com/elementsproject/glightning/jrpc2"
@@ -1160,6 +1163,24 @@ func (c *GetPremiumRate) New() interface{} {
11601163
}
11611164
}
11621165

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+
11631184
func (c *GetPremiumRate) Call() (jrpc2.Result, error) {
11641185
if !c.cl.isReady {
11651186
return nil, ErrWaitingForReady
@@ -1169,11 +1190,11 @@ func (c *GetPremiumRate) Call() (jrpc2.Result, error) {
11691190
if err != nil {
11701191
return nil, fmt.Errorf("error getting premium rate: %v", err)
11711192
}
1172-
return &peerswaprpc.PremiumRate{
1193+
return formatProtoMessage(&peerswaprpc.PremiumRate{
11731194
Asset: peerswaprpc.ToAssetType(e.Asset()),
11741195
Operation: peerswaprpc.ToOperationType(e.Operation()),
11751196
PremiumRatePpm: e.PremiumRatePPM().Value(),
1176-
}, nil
1197+
})
11771198
}
11781199

11791200
func (c *GetPremiumRate) Get(client *ClightningClient) jrpc2.ServerMethod {
@@ -1221,11 +1242,11 @@ func (c *UpdatePremiumRate) Call() (jrpc2.Result, error) {
12211242
if err != nil {
12221243
return nil, fmt.Errorf("error setting premium rate: %v", err)
12231244
}
1224-
return &peerswaprpc.PremiumRate{
1245+
return formatProtoMessage(&peerswaprpc.PremiumRate{
12251246
Asset: peerswaprpc.ToAssetType(rate.Asset()),
12261247
Operation: peerswaprpc.ToOperationType(rate.Operation()),
12271248
PremiumRatePpm: rate.PremiumRatePPM().Value(),
1228-
}, nil
1249+
})
12291250
}
12301251

12311252
func (c *UpdatePremiumRate) Get(client *ClightningClient) jrpc2.ServerMethod {
@@ -1268,11 +1289,11 @@ func (c *DeletePremiumRate) Call() (jrpc2.Result, error) {
12681289
if err != nil {
12691290
return nil, fmt.Errorf("error deleting premium rate: %v", err)
12701291
}
1271-
return &peerswaprpc.PremiumRate{
1292+
return formatProtoMessage(&peerswaprpc.PremiumRate{
12721293
Asset: peerswaprpc.ToAssetType(toPremiumAssetType(c.Asset)),
12731294
Operation: peerswaprpc.ToOperationType(toPremiumOperationType(c.Operation)),
12741295
PremiumRatePpm: 0,
1275-
}, nil
1296+
})
12761297
}
12771298

12781299
func (c *DeletePremiumRate) Get(client *ClightningClient) jrpc2.ServerMethod {
@@ -1319,11 +1340,11 @@ func (c *UpdateGlobalPremiumRate) Call() (jrpc2.Result, error) {
13191340
if err != nil {
13201341
return nil, fmt.Errorf("error setting default premium rate: %v", err)
13211342
}
1322-
return &peerswaprpc.PremiumRate{
1343+
return formatProtoMessage(&peerswaprpc.PremiumRate{
13231344
Asset: peerswaprpc.ToAssetType(rate.Asset()),
13241345
Operation: peerswaprpc.ToOperationType(rate.Operation()),
13251346
PremiumRatePpm: rate.PremiumRatePPM().Value(),
1326-
}, nil
1347+
})
13271348
}
13281349

13291350
func (c *UpdateGlobalPremiumRate) Get(client *ClightningClient) jrpc2.ServerMethod {
@@ -1365,11 +1386,11 @@ func (c *GetGlobalPremiumRate) Call() (jrpc2.Result, error) {
13651386
if err != nil {
13661387
return nil, fmt.Errorf("error getting default premium rate: %v", err)
13671388
}
1368-
return &peerswaprpc.PremiumRate{
1389+
return formatProtoMessage(&peerswaprpc.PremiumRate{
13691390
Asset: peerswaprpc.ToAssetType(rate.Asset()),
13701391
Operation: peerswaprpc.ToOperationType(rate.Operation()),
13711392
PremiumRatePpm: rate.PremiumRatePPM().Value(),
1372-
}, nil
1393+
})
13731394
}
13741395

13751396
func (c *GetGlobalPremiumRate) Get(client *ClightningClient) jrpc2.ServerMethod {

0 commit comments

Comments
 (0)