odra icon indicating copy to clipboard operation
odra copied to clipboard

Custom storage layout.

Open zie1ony opened this issue 1 year ago • 1 comments

Casper Node doesn't offer the ability to query the getter entry point. It forced (as I predicted long time ago) developers to use internal storage structure to obtain data from the contract. It means it's not enough to know entry points of a contract, also storage structure should be specified.

One of a Casper DEXs, https://friendly.market, allows to add custom tokens. I added a token implemented in Odra, but even, that it has all the right entry points, it can't be used, because they require name, symbol and balances exactly like it is implemented in https://github.com/casper-ecosystem/cep18 using named keys.

Having that said I propose to allow for custom data layouts to be ecosystem-compatible. It could look like:

pub struct CustomStorageLayout;

#[odra::module(layout = CustomStorageLayout)]
pub struct CasperEcosystemCep18 {
   #[transparent]
   pub token: odra_modules::erc20::Erc20
}

More exploration is needed.

zie1ony avatar Feb 26 '24 05:02 zie1ony

One possible idea:

enum StorageKind {
    NamedKey(String), // named key
    Disctionary(String, String) // named key, key
}

trait StorageLayout {
    fn key(&self, index: u32, name: &str) -> StorageKind;
}

struct Cep18CasperLabsStorage;

impl StorageLayout for Cep18CasperLabsStorage {
    fn key(&self, index: u32, name: &str) -> StorageKind {
        match index {
            0 => StorageKind::NamedKey("total_supply".to_string()),
            1 => StorageKind::Disctionary("balances".to_string(), name.to_string()),
            _ => panic!("Invalid index")
        }
    }
}

zie1ony avatar Mar 19 '24 09:03 zie1ony