# Docs helper
Docs helper allows to easily perform all the operations related to the commercio.network docs module.
# Provided operations
Creates a new transaction that allows to share the document associated with the given
metadata, documentid,recipientsand with the senderwallet. Optional fields arecontentUri,doSign,checksum,feeand the broadcastingmode.If
encryptedDatais specified, encrypts the proper data and optionalaesKeyfor the specifiedrecipientsand then sends the transaction to the blockchain. IfdoSignis provided then also thechecksumfield is required.suspend fun shareDocument( id: String, metadata: CommercioDoc.Metadata, recipients: List<Did>, wallet: Wallet, doSign: CommercioDoc.CommercioDoSign? = null, checksum: CommercioDoc.Checksum? = null, aesKey: SecretKey = KeysHelper.generateAesKey(), encryptedData: List<EncryptedData> = listOf(), fee: StdFee? = null, contentUri: String = "", mode: BroadcastingMode? = null ): TxResponse1
2
3
4
5
6
7
8
9
10
11
12
13Create a new transaction that allows to share a list of previously generated documents
commercioDocsListsigning the transaction withwallet. Optionallyfeeand broadcastingmodeparameters can be specified.suspend fun shareDocumentsList( commercioDocs: List<CommercioDoc>, wallet: Wallet, fee: StdFee? = null, mode: BroadcastingMode? = null ): TxResponse1
2
3
4
5
6Returns the list of all the
CommercioDocthat the specifiedaddresshas sent.suspend fun getSentDocuments(address: String, networkInfo: NetworkInfo): List<CommercioDoc>1Returns the list of all the
CommercioDocthat the specifiedaddresshas received.suspend fun getReceivedDocuments(address: String, networkInfo: NetworkInfo): List<CommercioDoc>1Creates a new transaction which tells the
recipientthat the document having the specifieddocumentIdand present inside the transaction with hashtxHashhas been properly seen; optionallyproofof reading,feeand broadcastingmode.suspend fun sendDocumentReceipt( recipient: Did, txHash: String, documentId: String, proof: String = "", wallet: Wallet, fee: StdFee? = null, mode: BroadcastingMode? = null ): TxResponse1
2
3
4
5
6
7
8
9Creates a new transaction which sends a list of previously generated receipts
commercioDocReceiptsList. Optionallyfeeand broadcastingmodeparameters can be specified.suspend fun sendDocumentReceiptsList( commercioDocReceipts: List<CommercioDocReceipt>, wallet: Wallet, fee: StdFee? = null, mode: BroadcastingMode? = null ): TxResponse1
2
3
4
5
6Returns the list of all the
CommercioDocReceiptthat have been sent from the givenaddress.suspend fun getSentReceipts(address: String, networkInfo: NetworkInfo): List<CommercioDocReceipt>1Returns the list of all the
CommercioDocReceiptthat have been received from the givenaddresssuspend fun getReceivedReceipts(address: String, networkInfo: NetworkInfo): List<CommercioDocReceipt>1
# Usage examples
val info = NetworkInfo(
bech32Hrp = "did:com:",
lcdUrl = "http://localhost:1317"
)
val userMnemonic = listOf(
"will",
"hard",
"topic",
"spray",
"beyond",
"ostrich",
"moral",
"morning",
"gas",
"loyal",
"couch",
"horn",
"boss",
"across",
"age",
"post",
"october",
"blur",
"piece",
"wheel",
"film",
"notable",
"word",
"man"
)
val senderWallet = Wallet.derive(mnemonic = userMnemonic, networkInfo = info)
val recipientMnemonic = listOf(
"crisp",
"become",
"thumb",
"fetch",
"forest",
"senior",
"polar",
"slush",
"wise",
"wash",
"doctor",
"sunset",
"skate",
"disease",
"power",
"tool",
"sock",
"upper",
"diary",
"what",
"trap",
"artist",
"wood",
"cereal"
)
val recipientWallet = Wallet.derive(recipientMnemonic, info)
val recipientDid = Did(senderWallet.bech32Address)
val metadata = CommercioDoc.Metadata(
contentUri = "https://example.com/document/metadata",
schema = CommercioDoc.Metadata.Schema(
uri = "https://example.com/custom/metadata/schema",
version = "1.0.0"
)
)
val docRecipientDid = Did(recipientWallet.bech32Address)
val docId = UUID.randomUUID().toString()
try {
// --- Share a document
val response = DocsHelper.shareDocument(
id = docId,
contentUri = "https://example.com/document",
metadata = metadata,
recipients = listOf(recipientDid),
fee = StdFee(gas = "200000", amount = listOf(StdCoin(denom = "ucommercio", amount = "10000"))),
wallet = senderWallet
)
val txHash = (response as TxResponse.Successful).txHash
// --- Send receipt
DocsHelper.sendDocumentReceipt(
recipient = recipientDid,
txHash = txHash,
documentId = docId,
wallet = recipientWallet
)
} catch (e: Exception) {
throw e
}
// --- getSentDocuments
val sentDocs = DocsHelper.getSentDocuments(
address = senderWallet.bech32Address,
networkInfo = networkInfo
)
print("\nsentDocs: $sentDocs\n\n")
// --- getReceivedDocuments
val receivedDocs = DocsHelper.getReceivedDocuments(
address = recipientWallet.bech32Address,
networkInfo = networkInfo
)
print("\nreceivedDocs: $receivedDocs\n\n")
// --- getSentReceipts
val sentReceipts = DocsHelper.getSentReceipts(
address = senderWallet.bech32Address,
networkInfo = networkInfo
)
print("\nsentReceipts: $sentReceipts\n")
// --- getReceivedReceipts
val receivedReceipts = DocsHelper.getReceivedReceipts(
address = recipientWallet.bech32Address,
networkInfo = networkInfo
)
print("\nreceivedReceipts: $receivedReceipts\n")
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127