@@ -27,6 +27,41 @@ class AssetManager {
2727 companion object {
2828 private val logger = LoggerFactory .getLogger(AssetManager ::class .java)
2929
30+ @JvmStatic
31+ fun createHTLC (
32+ proxy : CordaRPCOps ,
33+ assetType : String ,
34+ assetId : String ,
35+ recipientParty : String ,
36+ hashBase64 : String ,
37+ expiryTimeSecs : Long ,
38+ getAssetStateAndRefFlow : String ,
39+ deleteAssetStateCommand : CommandData
40+ ): Either <Error , String > {
41+ return try {
42+ AssetManager .logger.debug(" Sending asset-lock request to Corda as part of asset-exchange.\n " )
43+ val contractId = runCatching {
44+
45+ val assetAgreement = createAssetExchangeAgreement(assetType, assetId, recipientParty, " " )
46+ val lockInfo = createAssetLockInfo(hashBase64, expiryTimeSecs)
47+
48+ proxy.startFlow(::LockAsset , lockInfo, assetAgreement, getAssetStateAndRefFlow, deleteAssetStateCommand)
49+ .returnValue.get()
50+ }.fold({
51+ it.map { linearId ->
52+ AssetManager .logger.debug(" Locking asset was successful and the state was stored with linearId $linearId .\n " )
53+ linearId.toString()
54+ }
55+ }, {
56+ Left (Error (" Corda Network Error: Error running LockAsset flow: ${it.message} \n " ))
57+ })
58+ contractId
59+ } catch (e: Exception ) {
60+ AssetManager .logger.error(" Error locking asset in Corda network: ${e.message} \n " )
61+ Left (Error (" Error locking asset in Corda network: ${e.message} " ))
62+ }
63+ }
64+
3065 @JvmStatic
3166 fun createFungibleHTLC (
3267 proxy : CordaRPCOps ,
@@ -39,7 +74,7 @@ class AssetManager {
3974 deleteAssetStateCommand : CommandData
4075 ): Either <Error , String > {
4176 return try {
42- AssetManager .logger.debug(" Sending asset-lock request to Corda as part of asset-exchange.\n " )
77+ AssetManager .logger.debug(" Sending fungible asset-lock request to Corda as part of asset-exchange.\n " )
4378 val contractId = runCatching {
4479
4580 val assetAgreement = createFungibleAssetExchangeAgreement(tokenType, numUnits, recipientParty, " " )
@@ -49,16 +84,16 @@ class AssetManager {
4984 .returnValue.get()
5085 }.fold({
5186 it.map { linearId ->
52- AssetManager .logger.debug(" Locking asset was successful and the state was stored with linearId $linearId .\n " )
87+ AssetManager .logger.debug(" Locking fungible asset was successful and the state was stored with linearId $linearId .\n " )
5388 linearId.toString()
5489 }
5590 }, {
5691 Left (Error (" Corda Network Error: Error running LockFungibleAsset flow: ${it.message} \n " ))
5792 })
5893 contractId
5994 } catch (e: Exception ) {
60- AssetManager .logger.error(" Error locking asset in Corda network: ${e.message} \n " )
61- Left (Error (" Error locking asset in Corda network: ${e.message} " ))
95+ AssetManager .logger.error(" Error locking fungible asset in Corda network: ${e.message} \n " )
96+ Left (Error (" Error locking fungible asset in Corda network: ${e.message} " ))
6297 }
6398 }
6499
@@ -164,6 +199,22 @@ class AssetManager {
164199 }
165200 }
166201
202+ fun createAssetExchangeAgreement (
203+ assetType : String ,
204+ assetId : String ,
205+ recipient : String ,
206+ locker : String ): AssetLocks .AssetExchangeAgreement {
207+
208+ val assetAgreement = AssetLocks .AssetExchangeAgreement .newBuilder()
209+ .setType(assetType)
210+ .setId(assetId)
211+ .setLocker(locker)
212+ .setRecipient(recipient)
213+ .build()
214+
215+ return assetAgreement
216+ }
217+
167218 fun createFungibleAssetExchangeAgreement (
168219 tokenType : String ,
169220 numUnits : Long ,
0 commit comments