-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
45 enable tracking of blockchain txs (#47)
* enable tracking of logs and blockchain txs * update gradle-properties version * fix bugs - replace ifBlank with ifEmpty - fix getDidPublishOperationStatus call * resolve PR #47 comments
- Loading branch information
Showing
10 changed files
with
167 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
version=2.0.4-SNAPSHOT | ||
version=2.0.5-SNAPSHOT | ||
|
||
kotlin.code.style=official |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/com/rootsid/wal/library/mongoimpl/BlockchainTxLogDocStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.rootsid.wal.library.mongoimpl | ||
|
||
import com.mongodb.client.MongoCollection | ||
import com.mongodb.client.MongoDatabase | ||
import com.rootsid.wal.library.mongoimpl.config.DefaultMongoDbConn | ||
import com.rootsid.wal.library.mongoimpl.document.BlockchainTxLogDocument | ||
import com.rootsid.wal.library.wallet.model.BlockchainTxAction | ||
import com.rootsid.wal.library.wallet.model.BlockchainTxLog | ||
import com.rootsid.wal.library.wallet.storage.BlockchainTxLogStorage | ||
import org.litote.kmongo.* | ||
import java.util.* | ||
|
||
class BlockchainTxLogDocStorage(db: MongoDatabase? = null, collectionName: String = "tx_logs") : BlockchainTxLogStorage { | ||
private val txLogCollection: MongoCollection<BlockchainTxLogDocument> | ||
|
||
init { | ||
val mongoConn = db ?: DefaultMongoDbConn.open() | ||
|
||
this.txLogCollection = mongoConn.getCollection<BlockchainTxLogDocument>(collectionName) | ||
} | ||
|
||
override fun createTxLogObject(txLogId: String, walletId: String, action: BlockchainTxAction, description: String?): BlockchainTxLog { | ||
return BlockchainTxLogDocument(txLogId, walletId, action, description) | ||
} | ||
|
||
override fun insert(txLog: BlockchainTxLog): BlockchainTxLog { | ||
val result = txLogCollection.insertOne(txLog as BlockchainTxLogDocument) | ||
|
||
if (result.wasAcknowledged()) { | ||
return txLog | ||
} | ||
throw Exception("Failed to insert blockchain transaction log") | ||
} | ||
|
||
override fun list(): List<BlockchainTxLog> { | ||
return txLogCollection.find().toList() | ||
} | ||
|
||
/** | ||
* Update tx log with new entry * | ||
* @param txLog updated tx log data object | ||
* @return true if the operation was acknowledged | ||
*/ | ||
override fun update(txLog: BlockchainTxLog): Boolean { | ||
val result = txLogCollection.updateOne(txLog as BlockchainTxLogDocument, upsert()) | ||
return result.wasAcknowledged() | ||
} | ||
|
||
override fun findById(txLogId: String): BlockchainTxLog { | ||
return txLogCollection.findOneById(txLogId) ?: throw NoSuchElementException("No tx log found with id $txLogId") | ||
} | ||
|
||
override fun exists(txLogId: String): Boolean { | ||
return txLogCollection.findOneById(txLogId) != null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/rootsid/wal/library/mongoimpl/document/BlockchainTxLogDocument.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.rootsid.wal.library.mongoimpl.document | ||
|
||
import com.rootsid.wal.library.wallet.model.BlockchainTxAction | ||
import com.rootsid.wal.library.wallet.model.BlockchainTxLog | ||
import io.iohk.atala.prism.api.models.AtalaOperationStatus | ||
import io.iohk.atala.prism.api.models.AtalaOperationStatusEnum | ||
import kotlinx.serialization.Serializable | ||
|
||
data class BlockchainTxLogDocument( | ||
override val _id: String, | ||
override val walletId: String, | ||
override val action: BlockchainTxAction, | ||
override var description: String? = null, | ||
override var status: AtalaOperationStatusEnum = AtalaOperationStatus.PENDING_SUBMISSION, | ||
override var txId: String? = null, | ||
override var url: String? = null | ||
// val walletId: String | ||
// override var logEntries: MutableList<BlockchainTxLogEntry> = mutableListOf() | ||
) : BlockchainTxLog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 15 additions & 5 deletions
20
src/main/kotlin/com/rootsid/wal/library/wallet/model/BlockchainTxLog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
package com.rootsid.wal.library.wallet.model | ||
|
||
interface BlockchainTxLog { | ||
import io.iohk.atala.prism.api.models.AtalaOperationStatusEnum | ||
import java.io.Serializable | ||
|
||
interface BlockchainTxLog : Serializable { | ||
// use operationId as the primary key | ||
val _id: String | ||
val walletId: String | ||
var logEntries: MutableList<BlockchainTxLogEntry> | ||
|
||
// var logEntries: MutableList<BlockchainTxLogEntry> | ||
val action: BlockchainTxAction | ||
var status: AtalaOperationStatusEnum | ||
var description: String? | ||
var txId: String? | ||
var url: String? | ||
} | ||
|
||
/** | ||
* Add blockchain tx log | ||
* | ||
* @param entry blockchain transaction log entry | ||
*/ | ||
fun BlockchainTxLog.addBlockchainTxLog(entry: BlockchainTxLogEntry) { | ||
logEntries.add(entry) | ||
} | ||
// fun BlockchainTxLog.addBlockchainTxLog(entry: BlockchainTxLogEntry) { | ||
// logEntries.add(entry) | ||
// } |
Oops, something went wrong.