-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
taprpc: add marshal functions for universe RPC types
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[:], | ||
}, | ||
} | ||
} |