Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored usage of storage traits #583

Merged
merged 12 commits into from
Sep 14, 2022
Merged
37 changes: 29 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fuel-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ chrono = { version = "0.4", features = ["serde"] }
clap = { version = "3.1", features = ["derive"] }
cynic = { version = "1.0", features = ["surf"] }
derive_more = { version = "0.99" }
fuel-vm = { version = "0.16", features = ["serde"] }
fuel-vm = { version = "0.18", features = ["serde"] }
futures = "0.3"
hex = "0.4"
itertools = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion fuel-core-interfaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ anyhow = "1.0"
async-trait = "0.1"
chrono = { version = "0.4" }
derive_more = { version = "0.99" }
fuel-vm = { version = "0.16", default-features = false, features = ["random"] }
fuel-vm = { version = "0.18", default-features = false, features = ["random"] }
futures = "0.3"
lazy_static = "1.4"
parking_lot = "0.12"
Expand Down
86 changes: 85 additions & 1 deletion fuel-core-interfaces/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,91 @@
use crate::common::fuel_vm::prelude::InterpreterError;
pub use crate::common::fuel_vm::storage::{
ContractsAssets,
ContractsInfo,
ContractsRawCode,
ContractsState,
};
use crate::{
common::{
fuel_storage::Mappable,
fuel_tx::{
Transaction,
UtxoId,
},
fuel_types::{
Address,
Bytes32,
MessageId,
},
fuel_vm::prelude::InterpreterError,
},
model::{
Coin,
ConsensusId,
DaBlockHeight,
Message,
ValidatorId,
ValidatorStake,
},
relayer::StakingDiff,
};
use std::io::ErrorKind;
use thiserror::Error;

/// The storage table of coins. Each [`Coin`](crate::model::Coin) is represented by unique `UtxoId`.
pub struct Coins;

impl Mappable for Coins {
type Key = UtxoId;
type SetValue = Coin;
type GetValue = Self::SetValue;
}

/// The storage table of bridged Ethereum [`Message`](crate::model::Message)s.
pub struct Messages;

impl Mappable for Messages {
type Key = MessageId;
type SetValue = Message;
type GetValue = Self::SetValue;
}

/// The storage table of confirmed transactions.
pub struct Transactions;

impl Mappable for Transactions {
type Key = Bytes32;
type SetValue = Transaction;
type GetValue = Self::SetValue;
}

/// The storage table of delegate's indexes used by relayer.
/// Delegate index maps delegate `Address` with list of da block where delegation happened.
pub struct DelegatesIndexes;

impl Mappable for DelegatesIndexes {
type Key = Address;
type SetValue = [DaBlockHeight];
type GetValue = Vec<DaBlockHeight>;
}

/// The storage table of relayer validators set.
pub struct ValidatorsSet;

impl Mappable for ValidatorsSet {
type Key = ValidatorId;
type SetValue = (ValidatorStake, Option<ConsensusId>);
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
type GetValue = Self::SetValue;
}

/// The storage table of relayer staking diffs.
pub struct StakingDiffs;

impl Mappable for StakingDiffs {
type Key = DaBlockHeight;
type SetValue = StakingDiff;
type GetValue = Self::SetValue;
}

#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
Expand Down
4 changes: 4 additions & 0 deletions fuel-core-interfaces/src/model/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use crate::{
#[cfg(graphql)]
use async_graphql::Enum;

/// Represents the user's coin for some asset with `asset_id`.
/// The `Coin` is either `CoinStatus::Spent` or `CoinStatus::Unspent`. If the coin is unspent,
/// it can be used as an input to the transaction and can be spent up to the `amount`.
/// After usage as an input of a transaction, the `Coin` becomes `CoinStatus::Spent`.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone)]
pub struct Coin {
Expand Down
Loading