Skip to main content

GenesisAllocator

Struct GenesisAllocator 

Source
pub struct GenesisAllocator<'a> { /* private fields */ }
Expand description

This helps create a custom genesis alloc by making it easy to add funded accounts with known signers to the genesis block.

§Example

let mut allocator = GenesisAllocator::default();

// This will add a genesis account to the alloc builder, with the provided balance. The
// signer for the account will be returned.
let (_signer, _addr) = allocator.new_funded_account(U256::from(100_000_000_000_000_000u128));

// You can also provide code for the account.
let code = Bytes::from_str("0x1234").unwrap();
let (_second_signer, _second_addr) =
    allocator.new_funded_account_with_code(U256::from(100_000_000_000_000_000u128), code);

// You can also add an account with a specific address.
// This will not return a signer, since the address is provided by the user and the signer
// may be unknown.
let addr = "0Ac1dF02185025F65202660F8167210A80dD5086".parse::<Address>().unwrap();
allocator.add_funded_account_with_address(addr, U256::from(100_000_000_000_000_000u128));

// Once you're done adding accounts, you can build the alloc.
let alloc = allocator.build();

Implementations§

Source§

impl<'a> GenesisAllocator<'a>

Source

pub fn new_with_rng<R>(rng: &'a mut R) -> Self
where R: RngCore,

Initialize a new alloc builder with the provided rng.

Source

pub fn with_rng<R>(self, rng: &'a mut R) -> Self
where R: RngCore + Debug,

Use the provided rng for generating key pairs.

Source

pub fn new_funded_account(&mut self, balance: U256) -> (Keypair, Address)

Add a funded account to the genesis alloc.

Returns the key pair for the account and the account’s address.

Source

pub fn new_funded_account_with_code( &mut self, balance: U256, code: Bytes, ) -> (Keypair, Address)

Add a funded account to the genesis alloc with the provided code.

Returns the key pair for the account and the account’s address.

Source

pub fn new_funded_account_with_storage( &mut self, balance: U256, storage: BTreeMap<B256, B256>, ) -> (Keypair, Address)

Adds a funded account to the genesis alloc with the provided storage.

Returns the key pair for the account and the account’s address.

Source

pub fn new_account_with_code_and_storage( &mut self, code: Bytes, storage: BTreeMap<B256, B256>, ) -> (Keypair, Address)

Adds an account with code and storage to the genesis alloc.

Returns the key pair for the account and the account’s address.

Source

pub fn new_account_with_code(&mut self, code: Bytes) -> (Keypair, Address)

Adds an account with code to the genesis alloc.

Returns the key pair for the account and the account’s address.

Source

pub fn add_funded_account_with_address( &mut self, address: Address, balance: U256, )

Add a funded account to the genesis alloc with the provided address.

Neither the key pair nor the account will be returned, since the address is provided by the user and the signer may be unknown.

Source

pub fn add_account(&mut self, account: GenesisAccount) -> Address

Adds the given [GenesisAccount] to the genesis alloc.

Returns the key pair for the account and the account’s address.

Source

pub fn get_account(&self, address: &Address) -> Option<&GenesisAccount>

Gets the account for the provided address.

If it does not exist, this returns None.

Source

pub fn get_account_mut( &mut self, address: &Address, ) -> Option<&mut GenesisAccount>

Gets a mutable version of the account for the provided address, if it exists.

Source

pub fn account_entry( &mut self, address: Address, ) -> Entry<'_, Address, GenesisAccount>

Gets an Entry for the provided address.

Source

pub fn build(self) -> AddressMap<GenesisAccount>

Build the genesis alloc.

Trait Implementations§

Source§

impl Debug for GenesisAllocator<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GenesisAllocator<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for GenesisAllocator<'a>

§

impl<'a> !Send for GenesisAllocator<'a>

§

impl<'a> !Sync for GenesisAllocator<'a>

§

impl<'a> !UnwindSafe for GenesisAllocator<'a>

§

impl<'a> Freeze for GenesisAllocator<'a>

§

impl<'a> Unpin for GenesisAllocator<'a>

§

impl<'a> UnsafeUnpin for GenesisAllocator<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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 T
where U: From<T>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> NonStaticAny for T
where T: ?Sized,

§

fn type_id(&self) -> TypeId

Returns the lifetime-erased type ID of self.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 56 bytes