Skip to content

Commit

Permalink
fix(weaver-asset-transfer): return proper error messages for pledge s…
Browse files Browse the repository at this point in the history
…tatus and claim status

Signed-off-by: Sandeep Nishad <sandeep.nishad1@ibm.com>
  • Loading branch information
sandeepnRES committed Dec 21, 2023
1 parent 083ea4f commit f8f6bcb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions weaver/core/network/fabric-interop-cc/libs/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,13 @@ func GetAssetPledgeStatus(ctx contractapi.TransactionContextInterface, pledgeId,
if err != nil {
return nil, pledgeBytes64, pledgeBytes64, err
}

// Match pledge with request parameters
if lookupPledge.Recipient != recipientCert || lookupPledge.RemoteNetworkID != recipientNetworkId {
return nil, pledgeBytes64, pledgeBytes64, nil // Return blank

// Match claim with request parameters
if lookupPledge.RemoteNetworkID != recipientNetworkId {
return nil, pledgeBytes64, pledgeBytes64, fmt.Errorf("No Pledge exists for recipient network id: %s", recipientNetworkId) // Return blank
}
if lookupPledge.Recipient != recipientCert {
return nil, pledgeBytes64, pledgeBytes64, fmt.Errorf("No Pledge exists for recipient: %s", recipientCert)
}

lookupPledgeBytes64, err := marshalAssetPledge(lookupPledge)
Expand Down Expand Up @@ -500,7 +503,7 @@ func GetAssetPledgeDetails(ctx contractapi.TransactionContextInterface, pledgeId
}

// GetAssetClaimStatus returns the asset claim status and present time (of invocation).
func GetAssetClaimStatus(ctx contractapi.TransactionContextInterface, pledgeId, recipientCert, pledger, pledgerNetworkId string, pledgeExpiryTimeSecs uint64, blankAssetJSON []byte) ([]byte, string, string, error) {
func GetAssetClaimStatus(ctx contractapi.TransactionContextInterface, pledgeId, recipientCert, pledgerNetworkId string, pledgeExpiryTimeSecs uint64, blankAssetJSON []byte) ([]byte, string, string, error) {
// (Optional) Ensure that this function is being called by the relay via the Fabric Interop CC

claimStatus := &common.AssetClaimStatus{
Expand Down Expand Up @@ -533,8 +536,11 @@ func GetAssetClaimStatus(ctx contractapi.TransactionContextInterface, pledgeId,
}

// Match claim with request parameters
if lookupClaim.RemoteNetworkID != pledgerNetworkId || lookupClaim.Recipient != recipientCert {
return nil, claimStatusBytes64, claimStatusBytes64, nil // Return blank
if lookupClaim.RemoteNetworkID != pledgerNetworkId {
return nil, claimStatusBytes64, claimStatusBytes64, fmt.Errorf("No claim exists for pledger network id: %s", pledgerNetworkId) // Return blank
}
if lookupClaim.Recipient != recipientCert {
return nil, claimStatusBytes64, claimStatusBytes64, fmt.Errorf("No claim exists for recipient: %s", recipientCert)
}
lookupClaim.ExpiryTimeSecs = claimStatus.ExpiryTimeSecs
lookupClaim.ExpirationStatus = claimStatus.ExpirationStatus
Expand Down
2 changes: 1 addition & 1 deletion weaver/samples/fabric/simpleassettransfer/bondasset.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (s *SmartContract) GetAssetClaimStatus(ctx contractapi.TransactionContextIn
}

// Fetch asset claim details using common (library) logic
claimAssetDetails, claimBytes64, blankClaimBytes64, err := wutils.GetAssetClaimStatus(ctx, pledgeId, recipientCert, pledger, pledgerNetworkId, pledgeExpiryTimeSecs, blankAssetJSON)
claimAssetDetails, claimBytes64, blankClaimBytes64, err := wutils.GetAssetClaimStatus(ctx, pledgeId, recipientCert, pledgerNetworkId, pledgeExpiryTimeSecs, blankAssetJSON)
if err != nil {
return blankClaimBytes64, err
}
Expand Down
2 changes: 1 addition & 1 deletion weaver/samples/fabric/simpleassettransfer/tokenasset.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (s *SmartContract) GetTokenAssetClaimStatus(ctx contractapi.TransactionCont
}

// Fetch asset claim details using common (library) logic
claimAssetDetails, claimBytes64, blankClaimBytes64, err := wutils.GetAssetClaimStatus(ctx, pledgeId, recipientCert, pledger, pledgerNetworkId, pledgeExpiryTimeSecs, blankAssetJSON)
claimAssetDetails, claimBytes64, blankClaimBytes64, err := wutils.GetAssetClaimStatus(ctx, pledgeId, recipientCert, pledgerNetworkId, pledgeExpiryTimeSecs, blankAssetJSON)
if err != nil {
return blankClaimBytes64, err
}
Expand Down

0 comments on commit f8f6bcb

Please sign in to comment.