Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Oct 5, 2023
1 parent 6900c6c commit 2af624b
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 142 deletions.
6 changes: 3 additions & 3 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3299,15 +3299,15 @@ func (r *rpcServer) SetFederationSyncConfig(ctx context.Context,
// Unmarshal general sync config.
var syncGeneralConfig *universe.FedGlobalSyncConfig
if req.GeneralSyncConfig != nil {
proofTypes, err := universe.ParseProofType(
req.GeneralSyncConfig.ProofTypes,
proofType, err := universe.ParseProofType(
req.GlobalSyncConfig.ProofType,
)
if err != nil {
return nil, fmt.Errorf("unable to parse proof "+
"types: %w", err)
}
syncGeneralConfig = &universe.FedGlobalSyncConfig{
ProofTypes: proofTypes,
ProofType: proofType,
}
}

Expand Down
58 changes: 47 additions & 11 deletions tapdb/universe_federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,12 @@ func (u *UniverseFederationDB) UpsertFederationSyncConfig(
var writeTx UniverseFederationOptions
return u.db.ExecTx(ctx, &writeTx, func(db UniverseServerStore) error {
// Upsert general federation sync config.
err := db.SetFederationGlobalSyncConfig(
ctx, globalSyncConfig.ProofTypes.String(),
)
params := SetFedGlobalSyncConfigParams{
ProofType: globalSyncConfig.ProofType.String(),
AllowSyncInsert: globalSyncConfig.AllowSyncInsert,
AllowSyncExport: globalSyncConfig.AllowSyncExport,
}
err := db.SetFederationGlobalSyncConfig(ctx, params)
if err != nil {
return err
}
Expand All @@ -251,14 +254,47 @@ func (u *UniverseFederationDB) UpsertFederationSyncConfig(
assetIDBytes = uniID.AssetID[:]
}

params := UpsertFedUniSyncConfigParams{
AssetID: assetIDBytes,
GroupKey: groupPubKey,
ProofType: config.ProofTypes.String(),
}
err := db.UpsertFederationUniSyncConfig(ctx, params)
if err != nil {
return err
// If the proof type is unspecified, then we'll set
// the config for both issuance and transfer proof
// type universes.
if config.UniverseID.ProofType == universe.ProofTypeUnspecified {
// Set config for issuance proof type universe.
proofType := universe.ProofTypeIssuance
err := db.UpsertFederationUniSyncConfig(
ctx, UpsertFedUniSyncConfigParams{
AssetID: assetIDBytes,
GroupKey: groupPubKey,
ProofType: proofType.String(),
},
)
if err != nil {
return err
}

// Set config for transfer proof type universe.
proofType = universe.ProofTypeTransfer
err = db.UpsertFederationUniSyncConfig(
ctx, UpsertFedUniSyncConfigParams{
AssetID: assetIDBytes,
GroupKey: groupPubKey,
ProofType: proofType.String(),
},
)
if err != nil {
return err
}
} else {
proofType := config.UniverseID.ProofType
err := db.UpsertFederationUniSyncConfig(
ctx, UpsertFedUniSyncConfigParams{
AssetID: assetIDBytes,
GroupKey: groupPubKey,
ProofType: proofType.String(),
},
)
if err != nil {
return err
}
}
}

Expand Down
Loading

0 comments on commit 2af624b

Please sign in to comment.