# 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
,recipients
and with the senderwallet
. Optional fields arecontentUri
,doSign
,checksum
,fee
and the broadcastingmode
.If
encryptedData
is specified, encrypts the proper data and optionalaesKey
for the specifiedrecipients
and then sends the transaction to the blockchain. IfdoSign
is provided then also thechecksum
field 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 ): TxResponse
1
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
commercioDocsList
signing the transaction withwallet
. Optionallyfee
and broadcastingmode
parameters can be specified.suspend fun shareDocumentsList( commercioDocs: List<CommercioDoc>, wallet: Wallet, fee: StdFee? = null, mode: BroadcastingMode? = null ): TxResponse
1
2
3
4
5
6Returns the list of all the
CommercioDoc
that the specifiedaddress
has sent.suspend fun getSentDocuments(address: String, networkInfo: NetworkInfo): List<CommercioDoc>
1Returns the list of all the
CommercioDoc
that the specifiedaddress
has received.suspend fun getReceivedDocuments(address: String, networkInfo: NetworkInfo): List<CommercioDoc>
1Creates a new transaction which tells the
recipient
that the document having the specifieddocumentId
and present inside the transaction with hashtxHash
has been properly seen; optionallyproof
of reading,fee
and broadcastingmode
.suspend fun sendDocumentReceipt( recipient: Did, txHash: String, documentId: String, proof: String = "", wallet: Wallet, fee: StdFee? = null, mode: BroadcastingMode? = null ): TxResponse
1
2
3
4
5
6
7
8
9Creates a new transaction which sends a list of previously generated receipts
commercioDocReceiptsList
. Optionallyfee
and broadcastingmode
parameters can be specified.suspend fun sendDocumentReceiptsList( commercioDocReceipts: List<CommercioDocReceipt>, wallet: Wallet, fee: StdFee? = null, mode: BroadcastingMode? = null ): TxResponse
1
2
3
4
5
6Returns the list of all the
CommercioDocReceipt
that have been sent from the givenaddress
.suspend fun getSentReceipts(address: String, networkInfo: NetworkInfo): List<CommercioDocReceipt>
1Returns the list of all the
CommercioDocReceipt
that have been received from the givenaddress
suspend 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