Struct drk::Drk

source ·
pub struct Drk {
    pub rpc_client: RpcClient,
}

Fields§

§rpc_client: RpcClient

Implementations§

source§

impl Drk

source

pub async fn request_airdrop( &self, faucet_endpoint: Url, amount: f64, address: PublicKey ) -> Result<String>

Request an airdrop of amount token_id tokens from a faucet. Returns a transaction ID on success.

source§

impl Drk

source

pub async fn transfer( &self, amount: &str, token_id: TokenId, recipient: PublicKey, dao: bool, dao_bulla: Option<String> ) -> Result<Transaction>

Create a payment transaction. Returns the transaction object on success.

source§

impl Drk

source

pub async fn init_swap( &self, value_send: u64, token_send: TokenId, value_recv: u64, token_recv: TokenId ) -> Result<PartialSwapData>

Initialize the first half of an atomic swap

source

pub async fn join_swap(&self, partial: PartialSwapData) -> Result<Transaction>

Create a full transaction by inspecting and verifying given partial swap data, making the other half, and joining all this into a Transaction object.

source

pub async fn inspect_swap(&self, bytes: Vec<u8>) -> Result<()>

Inspect and verify a given swap (half or full) transaction

source

pub async fn sign_swap(&self, tx: &mut Transaction) -> Result<()>

Sign a given transaction by retrieving the secret key from the encrypted note and prepending it to the transaction’s signatures.

source§

impl Drk

source

pub async fn dao_mint(&self, dao_id: u64) -> Result<Transaction>

Mint a DAO on-chain

source

pub async fn dao_propose( &self, dao_id: u64, recipient: PublicKey, amount: u64, token_id: TokenId ) -> Result<Transaction>

Create a DAO proposal

source

pub async fn dao_vote( &self, dao_id: u64, proposal_id: u64, vote_option: bool, weight: u64 ) -> Result<Transaction>

Vote on a DAO proposal

source

pub async fn dao_exec( &self, dao: Dao, proposal: DaoProposal ) -> Result<Transaction>

Import given DAO votes into the wallet This function is really bad but I’m also really tired and annoyed.

source§

impl Drk

source

pub async fn mint_token( &self, amount: &str, recipient: PublicKey, token_id: TokenId ) -> Result<Transaction>

Create a token mint transaction. Returns the transaction object on success.

source

pub async fn freeze_token(&self, token_id: TokenId) -> Result<Transaction>

Create a token freeze transaction. Returns the transaction object on success.

source§

impl Drk

source

pub async fn subscribe_blocks(&self, endpoint: Url) -> Result<()>

Subscribes to darkfid’s JSON-RPC notification endpoint that serves new finalized blocks. Upon receiving them, all the transactions are scanned and we check if any of them call the money contract, and if the payments are intended for us. If so, we decrypt them and append the metadata to our wallet.

source

async fn scan_block_dao(&self, block: &BlockInfo) -> Result<()>

scan_block_dao will go over transactions in a block and fetch the ones dealing with the dao contract. Then over all of them, try to see if any are related to us. If any are found, the metadata is extracted and placed into the wallet for future use.

source

async fn scan_block_money(&self, block: &BlockInfo) -> Result<()>

scan_block_money will go over transactions in a block and fetch the ones dealing with the money contract. Then over all of them, try to see if any are related to us. If any are found, the metadata is extracted and placed into the wallet for future use.

source

pub async fn lookup_zkas( &self, contract_id: &ContractId ) -> Result<Vec<(String, Vec<u8>)>>

Try to fetch zkas bincodes for the given ContractId.

source

pub async fn broadcast_tx(&self, tx: &Transaction) -> Result<String>

Broadcast a given transaction to darkfid and forward onto the network. Returns the transaction ID upon success

source

pub async fn simulate_tx(&self, tx: &Transaction) -> Result<bool>

Simulate the transaction with the state machine

source

async fn get_block_by_slot(&self, slot: u64) -> Result<Option<BlockInfo>>

Queries darkfid for a block with given slot

source

pub async fn get_tx(&self, tx_hash: &Hash) -> Result<Option<Transaction>>

Queries darkfid for a tx with given hash

source

pub async fn scan_blocks(&self, reset: bool) -> Result<()>

Scans the blockchain starting from the last scanned slot, for relevant money transfer transactions. If reset flag is provided, Merkle tree state and coins are reset, and start scanning from beginning. Alternatively, it looks for a checkpoint in the wallet to reset and start scanning from.

source

pub async fn subscribe_err_txs(&self, endpoint: Url) -> Result<()>

Subscribes to darkfid’s JSON-RPC notification endpoint that serves erroneous transactions rejections.

source§

impl Drk

source

pub async fn initialize_wallet(&self) -> Result<()>

Initialize wallet with tables for drk

source§

impl Drk

source

pub async fn initialize_dao(&self) -> Result<()>

Initialize wallet with tables for the DAO contract

source

pub async fn get_dao_secrets(&self) -> Result<Vec<SecretKey>>

Fetch all DAO secret keys from the wallet

source

pub async fn put_dao_trees( &self, daos_tree: &MerkleTree, proposals_tree: &MerkleTree ) -> Result<()>

Replace the DAO Merkle trees in the wallet.

source

pub async fn get_dao_trees(&self) -> Result<(MerkleTree, MerkleTree)>

Fetch DAO Merkle trees from the wallet

source

pub async fn reset_dao_trees(&self) -> Result<()>

Reset the DAO Merkle trees in the wallet

source

pub async fn reset_daos(&self) -> Result<()>

Reset confirmed DAOs in the wallet

source

pub async fn reset_dao_proposals(&self) -> Result<()>

source

pub async fn reset_dao_votes(&self) -> Result<()>

source

pub async fn get_dao_id_by_alias(&self, alias_filter: &str) -> Result<u64>

source

pub async fn get_dao_id(&self, alias: &str) -> Result<u64>

Convenience function. Interprets the alias either as the DAO alias or its ID

source

pub async fn import_dao( &self, dao_name: String, dao_params: DaoParams ) -> Result<()>

Import given DAO params into the wallet with a given name.

source

pub async fn dao_list(&self, dao_id: Option<u64>) -> Result<()>

List DAO(s) imported in the wallet. If an ID is given, just print the metadata for that specific one, if found.

source

async fn dao_list_single(&self, dao_id: u64) -> Result<()>

source

pub async fn get_dao_by_id(&self, dao_id: u64) -> Result<Dao>

Fetch a DAO given a numeric ID

source

pub async fn get_daos(&self) -> Result<Vec<Dao>>

Fetch all known DAOs from the wallet.

source

pub async fn dao_balance(&self, dao_id: u64) -> Result<HashMap<String, u64>>

Fetch known unspent balances from the wallet for the given DAO ID

source

pub async fn get_dao_proposals(&self, dao_id: u64) -> Result<Vec<DaoProposal>>

Fetch all known DAO proposals from the wallet given a DAO ID

source

pub async fn get_dao_proposal_by_id( &self, proposal_id: u64 ) -> Result<DaoProposal>

Fetch a DAO proposal by its ID

source

pub async fn get_dao_proposal_votes( &self, proposal_id: u64 ) -> Result<Vec<DaoVote>>

source

pub async fn apply_tx_dao_data( &self, tx: &Transaction, confirm: bool ) -> Result<()>

Append data related to DAO contract transactions into the wallet database. Optionally, if confirm is true, also append the data in the Merkle trees, etc.

source

pub async fn confirm_daos(&self, daos: &[Dao]) -> Result<()>

Confirm already imported DAO metadata into the wallet. Here we just write the leaf position, tx hash, and call index. Panics if the fields are None.

source

pub async fn unconfirm_daos(&self, daos: &[Dao]) -> Result<()>

Unconfirm imported DAOs by removing the leaf position, txid, and call index.

source

pub async fn put_dao_proposals(&self, proposals: &[DaoProposal]) -> Result<()>

Import given DAO proposals into the wallet

source

pub async fn put_dao_votes(&self, votes: &[DaoVote]) -> Result<()>

Import given DAO votes into the wallet

source§

impl Drk

source

pub async fn initialize_money(&self) -> Result<()>

Initialize wallet with tables for the Money contract

source

pub async fn money_keygen(&self) -> Result<()>

Generate a new keypair and place it into the wallet.

source

pub async fn get_money_secrets(&self) -> Result<Vec<SecretKey>>

Fetch all secret keys from the wallet

source

pub async fn import_money_secrets( &self, secrets: Vec<SecretKey> ) -> Result<Vec<PublicKey>>

Import given secret keys into the wallet. The query uses INSERT, so if the key already exists, it will be skipped. Returns the respective PublicKey objects for the imported keys.

source

pub async fn wallet_address(&self, idx: u64) -> Result<PublicKey>

Fetch pubkeys from the wallet and return the requested index.

source

pub async fn get_coins(&self, fetch_spent: bool) -> Result<Vec<(OwnCoin, bool)>>

Fetch all coins and their metadata related to the Money contract from the wallet. Optionally also fetch spent ones. The boolean in the returned tuple notes if the coin was marked as spent.

source

pub async fn mark_spent_coin(&self, coin: &Coin) -> Result<()>

Mark a coin in the wallet as spent

source

pub async fn mark_spent_coins(&self, nullifiers: &[Nullifier]) -> Result<()>

Marks all coins in the wallet as spent, if their nullifier is in the given set

source

pub async fn unspend_coin(&self, coin: &Coin) -> Result<()>

Mark a given coin in the wallet as unspent

source

pub async fn put_money_tree(&self, tree: &MerkleTree) -> Result<()>

Replace the Money Merkle tree in the wallet.

source

pub async fn get_money_tree(&self) -> Result<MerkleTree>

Fetch the Money Merkle tree from the wallet

source

pub async fn reset_money_tree(&self) -> Result<()>

Reset the Money Merkle tree in the wallet

source

pub async fn reset_money_coins(&self) -> Result<()>

Reset the Money coins in the wallet

source

pub async fn money_balance(&self) -> Result<HashMap<String, u64>>

Fetch known unspent balances from the wallet and return them as a hashmap.

source

pub async fn apply_tx_money_data( &self, tx: &Transaction, _confirm: bool ) -> Result<()>

Append data related to Money contract transactions into the wallet database.

source

pub async fn last_scanned_slot(&self) -> Result<u64>

Get the last scanned slot from the wallet

source

pub async fn add_alias(&self, alias: String, token_id: TokenId) -> Result<()>

Create an alias record for provided Token ID

source

pub async fn get_aliases( &self, alias_filter: Option<String>, token_id_filter: Option<TokenId> ) -> Result<HashMap<String, TokenId>>

Fetch all aliases from the wallet. Optionally filter using alias name and/or token id.

source

pub async fn get_aliases_mapped_by_token( &self ) -> Result<HashMap<String, String>>

Fetch all aliases from the wallet, mapped by token id.

source

pub async fn get_token(&self, input: String) -> Result<TokenId>

Retrieve token by provided string. Input string represents either an alias or a token id.

source

pub async fn remove_alias(&self, alias: String) -> Result<()>

Create an alias record for provided Token ID

source§

impl Drk

source

pub async fn import_mint_authority( &self, mint_authority: SecretKey ) -> Result<()>

Import a token mint authority into the wallet

source

pub async fn list_tokens(&self) -> Result<Vec<(TokenId, SecretKey, bool)>>

source§

impl Drk

source

pub async fn get_txs_history(&self) -> Result<Vec<(String, String)>>

Fetch all transactions history records, excluding bytes column.

source

pub async fn get_tx_history_record( &self, tx_hash: &str ) -> Result<(String, String, Transaction)>

Get a transaction history record.

source

pub async fn insert_tx_history_record(&self, tx: &Transaction) -> Result<()>

Insert a Transaction history record into the wallet.

source

pub async fn update_tx_history_record_status( &self, tx_hash: &str, status: &str ) -> Result<()>

Update a transactions history record status to the given one.

source

pub async fn update_tx_history_records_status( &self, txs: &Vec<Transaction>, status: &str ) -> Result<()>

Update given transactions history record statuses to the given one.

source

pub async fn update_all_tx_history_records_status( &self, status: &str ) -> Result<()>

Update all transaction history records statuses to the given one.

source§

impl Drk

source

pub(crate) async fn new(endpoint: Url) -> Result<Self>

source

pub(crate) async fn ping(&self) -> Result<()>

Auto Trait Implementations§

§

impl RefUnwindSafe for Drk

§

impl Send for Drk

§

impl Sync for Drk

§

impl Unpin for Drk

§

impl UnwindSafe for Drk

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Conv for T

source§

fn conv<T>(self) -> Twhere Self: Into<T>,

Converts self into T using Into<T>. Read more
source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> FmtForward for T

source§

fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
source§

fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
source§

fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
source§

fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
source§

fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> LayoutRaw for T

source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
source§

impl<T> Pipe for Twhere T: ?Sized,

source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
source§

fn pipe_deref_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> Rwhere Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> Tap for T

source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
source§

impl<T> TryConv for T

source§

fn try_conv<T>(self) -> Result<T, Self::Error>where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcastable for Twhere T: Any + Send + Sync + 'static,

source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
source§

fn upcast_any_box(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

upcast boxed dyn
source§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more