Skip to content

Commit

Permalink
fix(corda-simple-app): use correct bond asset flows and contracts for…
Browse files Browse the repository at this point in the history
… bond asset exchange

    corda-simple-app: fix typo for partyb twice in initNetworkId.sh

Signed-off-by: Sandeep Nishad <[email protected]>
  • Loading branch information
sandeepnRES committed Jul 30, 2024
1 parent 81b75c3 commit b339b58
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test_weaver-asset-exchange-corda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
cat tmp.out
# Claim asset
CORDA_PORT=10006 ./clients/build/install/clients/bin/clients claim-asset -cid $CID -s secrettext 1> tmp.out
CORDA_PORT=10006 ./clients/build/install/clients/bin/clients claim-asset -f -cid $CID -s secrettext 1> tmp.out
cat tmp.out | grep "Asset Claim Response: Right" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
Expand All @@ -121,7 +121,7 @@ jobs:
cat tmp.out
## Unlock asset
CORDA_PORT=10006 ./clients/build/install/clients/bin/clients unlock-asset -cid $CID 1> tmp.out
CORDA_PORT=10006 ./clients/build/install/clients/bin/clients unlock-asset -f -cid $CID 1> tmp.out
cat tmp.out | grep "Asset Unlock Response: Right" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
Expand Down Expand Up @@ -201,7 +201,7 @@ jobs:
cat tmp.out
# Claim asset
CORDA_PORT=10006 ./clients/build/install/clients/bin/clients claim-asset -cid $CID -s secrettext 1> tmp.out
CORDA_PORT=10006 ./clients/build/install/clients/bin/clients claim-asset -f -cid $CID -s secrettext 1> tmp.out
cat tmp.out | grep "Asset Claim Response: Right" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
Expand All @@ -217,7 +217,7 @@ jobs:
cat tmp.out
## Unlock asset
CORDA_PORT=10006 ./clients/build/install/clients/bin/clients unlock-asset -cid $CID 1> tmp.out
CORDA_PORT=10006 ./clients/build/install/clients/bin/clients unlock-asset -f -cid $CID 1> tmp.out
cat tmp.out | grep "Asset Unlock Response: Right" && COUNT=$(( COUNT + 1 )) && echo "PASS"
cat tmp.out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.hyperledger.cacti.weaver.sdk.corda.AssetManager
import org.hyperledger.cacti.weaver.sdk.corda.HashFunctions
import com.cordaSimpleApplication.state.AssetState
import com.cordaSimpleApplication.contract.AssetContract
import com.cordaSimpleApplication.contract.BondAssetContract


/**
Expand Down Expand Up @@ -94,8 +95,8 @@ class LockAssetCommand : CliktCommand(
hash,
nTimeout,
1, // nTimeout represents Duration
"com.cordaSimpleApplication.flow.RetrieveStateAndRef",
AssetContract.Commands.Delete(),
"com.cordaSimpleApplication.flow.RetrieveBondAssetStateAndRef",
BondAssetContract.Commands.Delete(),
issuer
)
}
Expand All @@ -117,6 +118,7 @@ class ClaimAssetCommand : CliktCommand(help = "Claim a locked asset. Only Recipi
val contractId: String? by option("-cid", "--contract-id", help="Contract/Linear Id for HTLC State")
val hash_fn: String? by option("-hfn", "--hash-fn", help="Hash Function to be used. Default: SHA256")
val secret: String? by option("-s", "--secret", help="Hash Pre-Image for the HTLC Claim")
val fungible: Boolean by option("-f", "--fungible", help="Fungible Asset Lock: True/False").flag(default = false)
override fun run() = runBlocking {
var hash: HashFunctions.Hash = HashFunctions.SHA256()
if(hash_fn == "SHA256") {
Expand All @@ -135,14 +137,26 @@ class ClaimAssetCommand : CliktCommand(help = "Claim a locked asset. Only Recipi
try {
val issuer = rpc.proxy.wellKnownPartyFromX500Name(CordaX500Name.parse(ISSUER_DN))!!
hash.setPreimage(secret!!)
val res = AssetManager.claimAssetInHTLC(
rpc.proxy,
contractId!!,
hash,
AssetContract.Commands.Issue(),
"com.cordaSimpleApplication.flow.UpdateAssetOwnerFromPointer",
issuer
)
var res: Any
if (fungible) {
res = AssetManager.claimAssetInHTLC(
rpc.proxy,
contractId!!,
hash,
AssetContract.Commands.Issue(),
"com.cordaSimpleApplication.flow.UpdateAssetOwnerFromPointer",
issuer
)
} else {
res = AssetManager.claimAssetInHTLC(
rpc.proxy,
contractId!!,
hash,
BondAssetContract.Commands.Issue(),
"com.cordaSimpleApplication.flow.UpdateBondAssetOwnerFromPointer",
issuer
)
}
println("Asset Claim Response: ${res}")
} catch (e: Exception) {
println("Error: ${e.toString()}")
Expand All @@ -159,6 +173,7 @@ class ClaimAssetCommand : CliktCommand(help = "Claim a locked asset. Only Recipi
class UnlockAssetCommand : CliktCommand(help = "Unlocks a locked asset after timeout. Only lockers's call will work.") {
val config by requireObject<Map<String, String>>()
val contractId: String? by option("-cid", "--contract-id", help="Contract/Linear Id for HTLC State")
val fungible: Boolean by option("-f", "--fungible", help="Fungible Asset Lock: True/False").flag(default = false)
override fun run() = runBlocking {
if (contractId == null) {
println("Arguments required: --contract-id.")
Expand All @@ -170,12 +185,22 @@ class UnlockAssetCommand : CliktCommand(help = "Unlocks a locked asset after tim
rpcPort = config["CORDA_PORT"]!!.toInt())
try {
val issuer = rpc.proxy.wellKnownPartyFromX500Name(CordaX500Name.parse(ISSUER_DN))!!
val res = AssetManager.reclaimAssetInHTLC(
rpc.proxy,
contractId!!,
AssetContract.Commands.Issue(),
issuer
)
var res: Any
if (fungible) {
res = AssetManager.reclaimAssetInHTLC(
rpc.proxy,
contractId!!,
AssetContract.Commands.Issue(),
issuer
)
} else {
res = AssetManager.reclaimAssetInHTLC(
rpc.proxy,
contractId!!,
BondAssetContract.Commands.Issue(),
issuer
)
}
println("Asset Unlock Response: ${res}")
} catch (e: Exception) {
println("Error: ${e.toString()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ then
then
MEMBERS+="O=PartyB, L=London, C=GB;"
fi
if [[ $(docker ps | grep corda_network2_partyb_1 | wc -l) == 1 ]]
if [[ $(docker ps | grep corda_network2_partyc_1 | wc -l) == 1 ]]
then
MEMBERS+="O=PartyC, L=London, C=GB;"
fi
Expand Down

0 comments on commit b339b58

Please sign in to comment.