Skip to content

Commit d123d87

Browse files
authored
add hashed vouchers (#273)
1 parent ea1b738 commit d123d87

File tree

6 files changed

+116
-15
lines changed

6 files changed

+116
-15
lines changed

contracts/FlowContractAudits.cdc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,21 @@ pub contract FlowContractAudits {
6868
// Auditors can create new vouchers and remove them
6969
pub resource Auditor {
7070

71-
// Create new voucher
71+
// Create new voucher with contract code
7272
pub fun addVoucher(address: Address?, recurrent: Bool, expiryOffset: UInt64?, code: String) {
73+
let codeHash = FlowContractAudits.hashContractCode(code)
74+
self.addVoucherHashed(address: address, recurrent: recurrent, expiryOffset: expiryOffset, codeHash: codeHash)
75+
}
76+
77+
// Create new voucher with hashed contract code
78+
pub fun addVoucherHashed(address: Address?, recurrent: Bool, expiryOffset: UInt64?, codeHash: String) {
7379

7480
// calculate expiry block height based on expiryOffset
7581
var expiryBlockHeight: UInt64? = nil
7682
if expiryOffset != nil {
7783
expiryBlockHeight = getCurrentBlock().height + expiryOffset!
7884
}
79-
80-
let codeHash = FlowContractAudits.hashContractCode(code)
85+
8186
let key = FlowContractAudits.generateVoucherKey(address: address, codeHash: codeHash)
8287

8388
// if a voucher with the same key exists, remove it first
@@ -115,6 +120,10 @@ pub contract FlowContractAudits {
115120
self.auditorCapability!.borrow()!.addVoucher(address: address, recurrent: recurrent, expiryOffset: expiryOffset, code: code)
116121
}
117122

123+
pub fun addVoucherHashed(address: Address?, recurrent: Bool, expiryOffset: UInt64?, codeHash: String) {
124+
self.auditorCapability!.borrow()!.addVoucherHashed(address: address, recurrent: recurrent, expiryOffset: expiryOffset, codeHash: codeHash)
125+
}
126+
118127
pub fun deleteVoucher(key: String) {
119128
self.auditorCapability!.borrow()!.deleteVoucher(key: key)
120129
}

lib/go/contracts/internal/assets/assets.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)