Skip to content

Commit

Permalink
rpc+universe: set unspecified universe ID proof type from asset proof
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Oct 5, 2023
1 parent 7011c99 commit fbb0619
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,17 @@ func (r *rpcServer) InsertProof(ctx context.Context,
return nil, err
}

// If universe proof type unspecified, set based on the provided asset
// proof.
if universeID.ProofType == universe.ProofTypeUnspecified {
universeID.ProofType, err = universe.NewProofTypeFromAssetProof(
assetLeaf.Proof,
)
if err != nil {
return nil, err
}
}

rpcsLog.Debugf("[InsertProof]: inserting proof at "+
"(universeID=%x, leafKey=%x)", universeID,
leafKey.UniverseKey())
Expand Down
13 changes: 13 additions & 0 deletions universe/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,19 @@ const (
ProofTypeTransfer
)

// NewProofTypeFromAssetProof returns the proof type for the given asset proof.
func NewProofTypeFromAssetProof(proof *proof.Proof) (ProofType, error) {
if proof == nil {
return ProofTypeUnspecified, fmt.Errorf("proof is nil")
}

if proof.Asset.HasGenesisWitness() {
return ProofTypeIssuance, nil
}

return ProofTypeTransfer, nil
}

// String returns a human-readable string representation of the proof type.
func (t ProofType) String() string {
switch t {
Expand Down

0 comments on commit fbb0619

Please sign in to comment.