77 "sync"
88 "time"
99
10+ "github.com/btcsuite/btcd/btcec/v2"
1011 "github.com/davecgh/go-spew/spew"
1112 "github.com/lightninglabs/taproot-assets/address"
1213 "github.com/lightninglabs/taproot-assets/asset"
@@ -807,29 +808,43 @@ func (f *FederationEnvoy) tryFetchServers() ([]ServerAddr, error) {
807808// SyncAssetInfo queries the universes in our federation for genesis and asset
808809// group information about the given asset ID.
809810func (f * FederationEnvoy ) SyncAssetInfo (ctx context.Context ,
810- assetID * asset.ID ) error {
811+ specifier asset.Specifier ) error {
811812
812- if assetID == nil {
813- return fmt . Errorf ( "no asset ID provided" )
813+ uniID := Identifier {
814+ ProofType : ProofTypeIssuance ,
814815 }
815816
817+ switch {
818+ case specifier .HasId () && specifier .HasGroupPubKey ():
819+ return fmt .Errorf ("must set either asset ID or group key for " +
820+ "asset sync" )
821+
822+ case ! specifier .HasId () && ! specifier .HasGroupPubKey ():
823+ return fmt .Errorf ("no asset ID or group key provided" )
824+ }
825+
826+ specifier .WhenId (func (id asset.ID ) {
827+ uniID .AssetID = id
828+ })
829+ specifier .WhenGroupPubKey (func (groupKey btcec.PublicKey ) {
830+ uniID .GroupKey = & groupKey
831+ })
832+
816833 // Fetch the set of universe servers in our federation.
817834 fedServers , err := f .tryFetchServers ()
818835 if err != nil {
819836 return err
820837 }
821838
822839 assetConfig := FedUniSyncConfig {
823- UniverseID : Identifier {
824- AssetID : * assetID ,
825- ProofType : ProofTypeIssuance ,
826- },
840+ UniverseID : uniID ,
827841 AllowSyncInsert : true ,
828842 AllowSyncExport : false ,
829843 }
830844 fullConfig := SyncConfigs {
831845 UniSyncConfigs : []* FedUniSyncConfig {& assetConfig },
832846 }
847+
833848 // We'll sync with Universe servers in parallel and collect the diffs
834849 // from any successful syncs. There can only be one diff per server, as
835850 // we're only syncing one universe root.
@@ -846,8 +861,8 @@ func (f *FederationEnvoy) SyncAssetInfo(ctx context.Context,
846861 // Sync failures are expected from Universe servers that do not
847862 // have a relevant universe root.
848863 if err != nil {
849- log .Warnf ("Asset lookup failed: asset_id =%v, " +
850- "remote_server=%v: %v" , assetID .String (),
864+ log .Warnf ("Asset lookup failed: id =%v, " +
865+ "remote_server=%v: %v" , uniID .String (),
851866 addr .HostStr (), err )
852867
853868 // We don't want to abort syncing here, as this might
@@ -863,8 +878,8 @@ func (f *FederationEnvoy) SyncAssetInfo(ctx context.Context,
863878 if len (syncDiff ) != 1 {
864879 log .Warnf ("Unexpected number of sync diffs " +
865880 "when looking up asset: num_diffs=%d, " +
866- "asset_id =%v, remote_server=%v" ,
867- len (syncDiff ), assetID .String (),
881+ "id =%v, remote_server=%v" ,
882+ len (syncDiff ), uniID .String (),
868883 addr .HostStr ())
869884
870885 // We don't want to abort syncing here, as this
@@ -891,12 +906,11 @@ func (f *FederationEnvoy) SyncAssetInfo(ctx context.Context,
891906
892907 syncDiffs := fn .Collect (returnedSyncDiffs )
893908 log .Infof ("Synced new Universe leaves for asset %v, diff_size=%v" ,
894- assetID .String (), len (syncDiffs ))
909+ uniID .String (), len (syncDiffs ))
895910
896- // TODO(jhb): Log successful syncs?
897911 if len (syncDiffs ) == 0 {
898912 return fmt .Errorf ("asset lookup failed for asset: %v" ,
899- assetID .String ())
913+ uniID .String ())
900914 }
901915
902916 return nil
0 commit comments