-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DRY kv/set * Fix missing selector * Rename selector * Add comments
- Loading branch information
Showing
3 changed files
with
44 additions
and
18 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
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,20 @@ | ||
import sbp from '@sbp/sbp' | ||
|
||
export default (sbp('sbp/selectors/register', { | ||
// This selector is a wrapper for the `chelonia/kv/set` selector that uses | ||
// the contract queue and allows referring to keys by name, with default key | ||
// names set to `csk` and `cek` for signatures and encryption, respectively. | ||
// For most 'simple' use cases, this selector is a better choice than | ||
// `chelonia/kv/set`. However, the `chelonia/kv/set` primitive is needed if | ||
// the queueing logic needs to be more advanced, the key to use requires | ||
// custom logic or _if the `onconflict` callback also needs to be queued_. | ||
'chelonia/kv/queuedSet': ({ contractID, key, data, onconflict, encryptionKeyName = 'cek', signingKeyName = 'csk' }) => { | ||
return sbp('chelonia/queueInvocation', contractID, () => { | ||
return sbp('chelonia/kv/set', contractID, key, data, { | ||
encryptionKeyId: sbp('chelonia/contract/currentKeyIdByName', contractID, encryptionKeyName), | ||
signingKeyId: sbp('chelonia/contract/currentKeyIdByName', contractID, signingKeyName), | ||
onconflict | ||
}) | ||
}) | ||
} | ||
}): string[]) |
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