@@ -73,21 +73,21 @@ struct UTXOJson: Codable {
73
73
}
74
74
}
75
75
76
- struct RGB20Json : Codable {
77
- let genesis : String
78
- let id : String
79
- let ticker : String
80
- let name : String
81
- let description : String ?
82
- let decimalPrecision : UInt8
83
- let date : String
84
- let knownCirculating : UInt64
85
- let issueLimit : UInt64 ?
76
+ public struct RGB20Json : Codable {
77
+ public let genesis : String
78
+ public let id : String
79
+ public let ticker : String
80
+ public let name : String
81
+ public let description : String ?
82
+ public let decimalPrecision : UInt8
83
+ public let date : String
84
+ public let knownCirculating : UInt64
85
+ public let issueLimit : UInt64 ?
86
86
}
87
87
88
- struct Transfer {
89
- let psbt : String
90
- let consignment : String ?
88
+ public struct Transfer {
89
+ public let psbt : String
90
+ public let consignment : String ?
91
91
}
92
92
93
93
extension CitadelVault {
@@ -101,7 +101,7 @@ extension CitadelVault {
101
101
102
102
private func processResponseToString( _ response: UnsafePointer < Int8 > ? ) throws -> String {
103
103
guard let response = response else {
104
- guard let err = self . lastError ( ) else {
104
+ guard let err = lastError ( ) else {
105
105
throw CitadelError ( " MyCitadel C API is broken " )
106
106
}
107
107
throw err
@@ -145,54 +145,59 @@ extension WalletContract {
145
145
146
146
extension CitadelVault {
147
147
internal func create( singleSig derivation: String , name: String , descriptorType: DescriptorType ) throws -> ContractJson {
148
- try self . createSeed ( )
149
- let pubkeyChain = try self . createScopedChain ( derivation: derivation)
148
+ print ( " Creating seed " )
149
+ try createSeed ( )
150
+ let pubkeyChain = try createScopedChain ( derivation: derivation)
150
151
let response = mycitadel_single_sig_create ( rpcClient, name, pubkeyChain, descriptorType. cDescriptorType ( ) ) ;
151
- return try JSONDecoder ( ) . decode ( ContractJson . self, from: self . processResponse ( response) )
152
+ return try JSONDecoder ( ) . decode ( ContractJson . self, from: processResponse ( response) )
152
153
}
153
154
154
155
internal func listContracts( ) throws -> [ ContractJson ] {
155
156
print ( " Listing contracts " )
156
157
let response = mycitadel_contract_list ( rpcClient)
157
- return try JSONDecoder ( ) . decode ( [ ContractJson ] . self, from: self . processResponse ( response) )
158
+ return try JSONDecoder ( ) . decode ( [ ContractJson ] . self, from: processResponse ( response) )
158
159
}
159
160
160
161
internal func operations( walletId: String ) throws -> [ TransferOperation ] {
161
162
print ( " Listing operations " )
162
163
let response = mycitadel_contract_operations ( rpcClient, walletId)
163
- return try JSONDecoder ( ) . decode ( [ TransferOperation ] . self, from: self . processResponse ( response) )
164
+ return try JSONDecoder ( ) . decode ( [ TransferOperation ] . self, from: processResponse ( response) )
164
165
}
165
166
166
167
internal func balance( walletId: String ) throws -> [ String : [ UTXOJson ] ] {
167
168
print ( " Requesting balance for \( walletId) " )
168
169
let response = mycitadel_contract_balance ( rpcClient, walletId, true , 20 )
169
- return try JSONDecoder ( ) . decode ( [ String : [ UTXOJson ] ] . self, from: self . processResponse ( response) )
170
+ return try JSONDecoder ( ) . decode ( [ String : [ UTXOJson ] ] . self, from: processResponse ( response) )
170
171
}
171
172
172
173
internal func listAssets( ) throws -> [ RGB20Json ] {
173
174
print ( " Listing assets " )
174
175
let response = mycitadel_asset_list ( rpcClient) ;
175
- return try JSONDecoder ( ) . decode ( [ RGB20Json ] . self, from: self . processResponse ( response) )
176
+ return try JSONDecoder ( ) . decode ( [ RGB20Json ] . self, from: processResponse ( response) )
176
177
}
177
178
178
179
internal func importRGB( genesisBech32 genesis: String ) throws -> RGB20Json {
180
+ print ( " Importing RGB asset " )
179
181
let response = mycitadel_asset_import ( rpcClient, genesis) ;
180
- return try JSONDecoder ( ) . decode ( RGB20Json . self, from: self . processResponse ( response) )
182
+ return try JSONDecoder ( ) . decode ( RGB20Json . self, from: processResponse ( response) )
181
183
}
182
184
183
185
public func nextAddress( forContractId contractId: String , useLegacySegWit legacy: Bool = false ) throws -> AddressDerivation {
186
+ print ( " Generating next avaliable address " )
184
187
let response = mycitadel_address_create ( rpcClient, contractId, false , legacy)
185
- return try JSONDecoder ( ) . decode ( AddressDerivation . self, from: self . processResponse ( response) )
188
+ return try JSONDecoder ( ) . decode ( AddressDerivation . self, from: processResponse ( response) )
186
189
}
187
190
188
191
internal func usedAddresses( forContractId contractId: String ) throws -> [ AddressDerivation ] {
192
+ print ( " Listing used addresses " )
189
193
let response = mycitadel_address_list ( rpcClient, contractId, false , 0 )
190
- return try JSONDecoder ( ) . decode ( [ String : UInt32 ] . self, from: self . processResponse ( response) )
194
+ return try JSONDecoder ( ) . decode ( [ String : UInt32 ] . self, from: processResponse ( response) )
191
195
. map { ( address, index) in AddressDerivation ( address: address, derivation: [ index] ) }
192
196
}
193
197
194
- internal func invoice( usingFormat format: InvoiceType , receiveTo contractId: String , nominatedIn assetId: String ? , value: UInt64 ? , useLegacySegWit legacy: Bool = false ) throws -> String {
195
- let invoice = mycitadel_invoice_create ( rpcClient, format. cType ( ) , contractId, assetId ?? nil , value ?? 0 , nil , nil , false , legacy)
198
+ internal func invoice( usingFormat format: InvoiceType , receiveTo contractId: String , nominatedIn assetId: String ? , value: UInt64 ? , from merchant: String ? = nil , purpose: String ? = nil , useLegacySegWit legacy: Bool = false ) throws -> String {
199
+ print ( " Creating invoice " )
200
+ let invoice = mycitadel_invoice_create ( rpcClient, format. cType ( ) , contractId, assetId ?? nil , value ?? 0 , merchant ?? nil , purpose ?? nil , false , legacy)
196
201
return try processResponseToString ( invoice)
197
202
}
198
203
@@ -207,9 +212,10 @@ extension CitadelVault {
207
212
*/
208
213
209
214
internal func pay( from contractId: String , invoice: String , value: UInt64 ? = nil , fee: UInt64 , giveaway: UInt64 ? = nil ) throws -> Transfer {
215
+ print ( " Paying invoice " )
210
216
let transfer = mycitadel_invoice_pay ( rpcClient, contractId, invoice, value ?? 0 , fee, giveaway ?? 0 )
211
217
if !transfer. success {
212
- guard let err = self . lastError ( ) else {
218
+ guard let err = lastError ( ) else {
213
219
throw CitadelError ( " MyCitadel C API is broken " )
214
220
}
215
221
throw err
@@ -229,11 +235,13 @@ extension CitadelVault {
229
235
}
230
236
231
237
internal func publish( psbt: String ) throws -> String {
238
+ print ( " Signing and publishing transaction " )
232
239
let txid = mycitadel_psbt_publish ( rpcClient, psbt)
233
240
return try processResponseToString ( txid)
234
241
}
235
242
236
243
internal func accept( consignment: String ) throws -> String {
244
+ print ( " Accepting consignment " )
237
245
let status = mycitadel_invoice_accept ( rpcClient, consignment)
238
246
return try processResponseToString ( status)
239
247
}
0 commit comments