-
Notifications
You must be signed in to change notification settings - Fork 5
Bindings source code conventions
Daniel Zduniak edited this page Mar 9, 2023
·
11 revisions
When modifying bindings source code, please stick to the following conventions.
This:
pub struct ZcashDiversifier(Diversifier);
NOT this:
pub struct ZcashDiversifier {
inner: Diversifier,
}
When possible (no type names clashing):
use zcash_primitives::legacy::TransparentAddress;
// ...
pub struct ZcashTransparentAddress(TransparentAddress);
Instead of using longer paths like:
pub struct ZcashTransparentAddress(zcash_primitives::legacy::TransparentAddress);
Constructor named new
in librustzcash
- simply use a constructor
in .udl
.
Constructor with a name different than new
use Name={constructor name}
attribute in .udl
:
interface ZcashOrchardDiversifier {
[Name=from_bytes, Throws=ZcashError]
constructor(sequence<u8> bytes);
};
Unless it's the only constructor - then you may consider simply using new
in bindings Rust code and constructor
without Name
attribute in .udl
.
Constructors returning Option
- use Result
in bindings and ZcashError
in .udl
(chose or create a new error that seems the most appropriate) - uniffi-rs
does not support constructors returning optional types.
interface ZcashAccountPrivKey {
// ...
[Name=from_bytes, Throws=ZcashError]
constructor(sequence<u8> data);