Skip to content

Commit 565e724

Browse files
committed
added timeSpec in SDK
Signed-off-by: Krishnasuri Narayanam <[email protected]>
1 parent 1fa1929 commit 565e724

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

sdks/corda/src/main/kotlin/com/weaver/corda/sdk/AssetManager.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ class AssetManager {
3535
recipientParty: String,
3636
hashBase64: String,
3737
expiryTimeSecs: Long,
38+
timeSpec: Int,
3839
getAssetStateAndRefFlow: String,
3940
deleteAssetStateCommand: CommandData
4041
): Either<Error, String> {
4142
return try {
4243
AssetManager.logger.debug("Sending asset-lock request to Corda as part of asset-exchange.\n")
43-
val contractId = runCatching {
4444

45+
val contractId = runCatching {
4546
val assetAgreement = createAssetExchangeAgreement(assetType, assetId, recipientParty, "")
46-
val lockInfo = createAssetLockInfo(hashBase64, expiryTimeSecs)
47+
val lockInfo = createAssetLockInfo(hashBase64, timeSpec, expiryTimeSecs)
4748

4849
proxy.startFlow(::LockAsset, lockInfo, assetAgreement, getAssetStateAndRefFlow, deleteAssetStateCommand)
4950
.returnValue.get()
@@ -70,6 +71,7 @@ class AssetManager {
7071
recipientParty: String,
7172
hashBase64: String,
7273
expiryTimeSecs: Long,
74+
timeSpec: Int,
7375
getAssetStateAndRefFlow: String,
7476
deleteAssetStateCommand: CommandData
7577
): Either<Error, String> {
@@ -78,7 +80,7 @@ class AssetManager {
7880
val contractId = runCatching {
7981

8082
val assetAgreement = createFungibleAssetExchangeAgreement(tokenType, numUnits, recipientParty, "")
81-
val lockInfo = createAssetLockInfo(hashBase64, expiryTimeSecs)
83+
val lockInfo = createAssetLockInfo(hashBase64, timeSpec, expiryTimeSecs)
8284

8385
proxy.startFlow(::LockFungibleAsset, lockInfo, assetAgreement, getAssetStateAndRefFlow, deleteAssetStateCommand)
8486
.returnValue.get()
@@ -100,7 +102,7 @@ class AssetManager {
100102
@JvmStatic
101103
fun claimAssetInHTLC(
102104
proxy: CordaRPCOps,
103-
contractId: net.corda.core.contracts.UniqueIdentifier,
105+
contractId: String,
104106
hashPreimage: String,
105107
createAssetStateCommand: CommandData,
106108
assetStateContractId: String,
@@ -132,7 +134,7 @@ class AssetManager {
132134
@JvmStatic
133135
fun reclaimAssetInHTLC(
134136
proxy: CordaRPCOps,
135-
contractId: net.corda.core.contracts.UniqueIdentifier,
137+
contractId: String,
136138
createAssetStateCommand: CommandData,
137139
assetStateContractId: String
138140
): Either<Error, SignedTransaction> {
@@ -160,7 +162,7 @@ class AssetManager {
160162
@JvmStatic
161163
fun isAssetLockedInHTLC(
162164
proxy: CordaRPCOps,
163-
contractId: net.corda.core.contracts.UniqueIdentifier
165+
contractId: String
164166
): Boolean {
165167
return try {
166168
AssetManager.logger.debug("Querying if asset is locked in Corda as part of asset-exchange.\n")
@@ -176,7 +178,7 @@ class AssetManager {
176178
@JvmStatic
177179
fun readHTLCStateByContractId(
178180
proxy: CordaRPCOps,
179-
contractId: net.corda.core.contracts.UniqueIdentifier
181+
contractId: String
180182
): Either<Error, StateAndRef<AssetExchangeHTLCState>> {
181183
return try {
182184
AssetManager.logger.debug("Querying asset-lock HTLC state from Corda as part of asset-exchange.\n")
@@ -233,10 +235,12 @@ class AssetManager {
233235

234236
fun createAssetLockInfo(
235237
hashBase64: String,
238+
timeSpec: Int,
236239
expiryTimeSecs: Long): AssetLocks.AssetLock {
237240

238241
val lockInfoHTLC = AssetLocks.AssetLockHTLC.newBuilder()
239242
.setHashBase64(ByteString.copyFrom(hashBase64.toByteArray()))
243+
.setTimeSpecValue(timeSpec)
240244
.setExpiryTimeSecs(expiryTimeSecs)
241245
.build()
242246

@@ -249,10 +253,10 @@ class AssetManager {
249253
}
250254

251255
fun createAssetClaimInfo(
252-
hashPreimageBase64: String): AssetLocks.AssetClaim {
256+
hashPreimage: String): AssetLocks.AssetClaim {
253257

254258
val claimInfoHTLC = AssetLocks.AssetClaimHTLC.newBuilder()
255-
.setHashPreimageBase64(ByteString.copyFrom(hashPreimageBase64.toByteArray()))
259+
.setHashPreimageBase64(ByteString.copyFrom(Base64.getEncoder().encodeToString(hashPreimage.toByteArray()).toByteArray()))
256260
.build()
257261

258262
val claimInfo = AssetLocks.AssetClaim.newBuilder()

0 commit comments

Comments
 (0)