Skip to content

Commit

Permalink
taprpc: add marshal functions for universe RPC types
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Sep 8, 2023
1 parent db10883 commit 8b464ee
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions taprpc/universerpc/marshal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package universerpc

import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/taproot-assets/asset"
)

// MarshalOutpoint marshals a wire.OutPoint into an RPC ready Outpoint.
//
// TODO(ffranr): Move this package's Outpoint type and this marshal function to
// somewhere more general.
func MarshalOutpoint(outPoint wire.OutPoint) *Outpoint {
return &Outpoint{
HashStr: outPoint.Hash.String(),
Index: int32(outPoint.Index),
}
}

// MarshalAssetKey returns an RPC ready AssetKey.
func MarshalAssetKey(outPoint wire.OutPoint,
scriptKeyPubKey *btcec.PublicKey) *AssetKey {

scriptKeyBytes := scriptKeyPubKey.SerializeCompressed()

return &AssetKey{
Outpoint: &AssetKey_Op{
Op: MarshalOutpoint(outPoint),
},
ScriptKey: &AssetKey_ScriptKeyBytes{
ScriptKeyBytes: scriptKeyBytes,
},
}
}

// MarshalUniverseID returns an RPC ready universe ID.
func MarshalUniverseID(assetID asset.ID) *ID {
// TODO(ffranr): Determine whether to use asset ID or group key.
return &ID{
Id: &ID_AssetId{
AssetId: assetID[:],
},
}
}

0 comments on commit 8b464ee

Please sign in to comment.