Skip to content

Commit 3e21462

Browse files
committed
rpcutils: move universe gRPC marshal functionality from taprpc
Move universe related gRPC marshalling functionality from the taprpc package to the rpcutils package as preparation for future modularization.
1 parent e41ddf2 commit 3e21462

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

itest/universe_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/lightninglabs/taproot-assets/fn"
1818
"github.com/lightninglabs/taproot-assets/internal/test"
1919
"github.com/lightninglabs/taproot-assets/mssmt"
20+
"github.com/lightninglabs/taproot-assets/rpcutils"
2021
"github.com/lightninglabs/taproot-assets/taprpc"
2122
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
2223
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
@@ -760,7 +761,7 @@ func testFederationSyncConfig(t *harnessTest) {
760761
AssetID: assetID1,
761762
ProofType: universe.ProofTypeIssuance,
762763
}
763-
uniIdRpc1 := unirpc.MarshalUniverseID(assetIDBytes1, nil)
764+
uniIdRpc1 := rpcutils.MarshalUniverseID(assetIDBytes1, nil)
764765
uniIdRpc1.ProofType = unirpc.ProofType_PROOF_TYPE_ISSUANCE
765766

766767
// Generate universe ID #2.
@@ -771,7 +772,7 @@ func testFederationSyncConfig(t *harnessTest) {
771772
GroupKey: groupKey2,
772773
ProofType: universe.ProofTypeTransfer,
773774
}
774-
uniIdRpc2 := unirpc.MarshalUniverseID(nil, groupKeyBytes2)
775+
uniIdRpc2 := rpcutils.MarshalUniverseID(nil, groupKeyBytes2)
775776
uniIdRpc2.ProofType = unirpc.ProofType_PROOF_TYPE_TRANSFER
776777

777778
// Set both the global and a universe specific federation sync configs.

proof/courier.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ func (c *UniverseRpcCourier) DeliverProof(ctx context.Context,
13281328

13291329
// Construct universe key.
13301330
outPoint := transitionProof.OutPoint()
1331-
assetKey := unirpc.MarshalAssetKey(
1331+
assetKey := rpcutils.MarshalAssetKey(
13321332
outPoint, proofAsset.ScriptKey.PubKey,
13331333
)
13341334
assetID := proofAsset.ID()
@@ -1342,7 +1342,7 @@ func (c *UniverseRpcCourier) DeliverProof(ctx context.Context,
13421342
groupPubKeyBytes = groupPubKey.SerializeCompressed()
13431343
}
13441344

1345-
universeID := unirpc.MarshalUniverseID(
1345+
universeID := rpcutils.MarshalUniverseID(
13461346
assetID[:], groupPubKeyBytes,
13471347
)
13481348
universeKey := unirpc.UniverseKey{
@@ -1424,10 +1424,10 @@ func (c *UniverseRpcCourier) ReceiveProof(ctx context.Context,
14241424
}
14251425

14261426
universeKey := unirpc.UniverseKey{
1427-
Id: unirpc.MarshalUniverseID(
1427+
Id: rpcutils.MarshalUniverseID(
14281428
loc.AssetID[:], groupKeyBytes,
14291429
),
1430-
LeafKey: unirpc.MarshalAssetKey(
1430+
LeafKey: rpcutils.MarshalAssetKey(
14311431
*loc.OutPoint, &loc.ScriptKey,
14321432
),
14331433
}

rpcserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6563,7 +6563,7 @@ func MarshalAssetFedSyncCfg(
65636563
if uniID.GroupKey != nil {
65646564
groupKeyBytes = uniID.GroupKey.SerializeCompressed()
65656565
}
6566-
uniIdRPC := unirpc.MarshalUniverseID(assetIDBytes, groupKeyBytes)
6566+
uniIdRPC := rpcutils.MarshalUniverseID(assetIDBytes, groupKeyBytes)
65676567

65686568
// Marshal proof type.
65696569
proofTypeRpc, err := MarshalUniProofType(uniID.ProofType)

taprpc/universerpc/marshal.go renamed to rpcutils/universe_marshal.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
package universerpc
1+
package rpcutils
22

33
import (
44
"github.com/btcsuite/btcd/btcec/v2"
55
"github.com/btcsuite/btcd/wire"
6+
"github.com/lightninglabs/taproot-assets/taprpc/universerpc"
67
)
78

89
// MarshalOutpoint marshals a wire.OutPoint into an RPC ready Outpoint.
9-
//
10-
// TODO(ffranr): Move this package's Outpoint type and this marshal function to
11-
// somewhere more general.
12-
func MarshalOutpoint(outPoint wire.OutPoint) *Outpoint {
13-
return &Outpoint{
10+
func MarshalOutpoint(outPoint wire.OutPoint) *universerpc.Outpoint {
11+
return &universerpc.Outpoint{
1412
HashStr: outPoint.Hash.String(),
1513
Index: int32(outPoint.Index),
1614
}
1715
}
1816

1917
// MarshalAssetKey returns an RPC ready AssetKey.
2018
func MarshalAssetKey(outPoint wire.OutPoint,
21-
scriptKeyPubKey *btcec.PublicKey) *AssetKey {
19+
scriptKeyPubKey *btcec.PublicKey) *universerpc.AssetKey {
2220

2321
scriptKeyBytes := scriptKeyPubKey.SerializeCompressed()
2422

25-
return &AssetKey{
26-
Outpoint: &AssetKey_Op{
23+
return &universerpc.AssetKey{
24+
Outpoint: &universerpc.AssetKey_Op{
2725
Op: MarshalOutpoint(outPoint),
2826
},
29-
ScriptKey: &AssetKey_ScriptKeyBytes{
27+
ScriptKey: &universerpc.AssetKey_ScriptKeyBytes{
3028
ScriptKeyBytes: scriptKeyBytes,
3129
},
3230
}
3331
}
3432

3533
// MarshalUniverseID returns an RPC ready universe ID.
36-
func MarshalUniverseID(assetIDBytes []byte, groupKeyBytes []byte) *ID {
34+
func MarshalUniverseID(assetIDBytes []byte,
35+
groupKeyBytes []byte) *universerpc.ID {
36+
3737
// We will marshal either a group key ID or an asset ID. If group key
3838
// bytes are given, we marshal a group key ID, otherwise we marshal an
3939
// asset ID.
4040
if groupKeyBytes != nil {
41-
return &ID{
42-
Id: &ID_GroupKey{
41+
return &universerpc.ID{
42+
Id: &universerpc.ID_GroupKey{
4343
GroupKey: groupKeyBytes,
4444
},
4545
}
4646
}
4747

48-
return &ID{
49-
Id: &ID_AssetId{
48+
return &universerpc.ID{
49+
Id: &universerpc.ID_AssetId{
5050
AssetId: assetIDBytes,
5151
},
5252
}

0 commit comments

Comments
 (0)