-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat pop api crate refactoring and test (#15)
* refactor: simplify api usage from contract * test: add NFT mint unit test to pop api extension --------- Co-authored-by: Frank Bell <frank@r0gue.io>
- Loading branch information
1 parent
ce62aa9
commit 20357df
Showing
13 changed files
with
252 additions
and
145 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,77 @@ | ||
#![cfg_attr(not(feature = "std"), no_std, no_main)] | ||
|
||
pub mod interfaces; | ||
pub mod impls; | ||
pub mod v0; | ||
|
||
use ink::{env::Environment, prelude::vec::Vec, ChainExtensionInstance}; | ||
use scale; | ||
Check warning on line 6 in pop-api/src/lib.rs GitHub Actions / clippythis import is redundant
|
||
use sp_runtime::MultiSignature; | ||
pub use v0::nfts; | ||
use v0::RuntimeCall; | ||
|
||
// Id used for identifying non-fungible collections. | ||
pub type CollectionId = u32; | ||
|
||
// Id used for identifying non-fungible items. | ||
pub type ItemId = u32; | ||
|
||
type AccountId = <ink::env::DefaultEnvironment as Environment>::AccountId; | ||
type Balance = <ink::env::DefaultEnvironment as Environment>::Balance; | ||
type BlockNumber = <ink::env::DefaultEnvironment as Environment>::BlockNumber; | ||
type Signature = MultiSignature; | ||
Check warning on line 20 in pop-api/src/lib.rs GitHub Actions / clippytype alias `Signature` is never used
|
||
type StringLimit = u32; | ||
type KeyLimit = u32; | ||
type MaxTips = u32; | ||
|
||
pub type Result<T> = core::result::Result<T, PopApiError>; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)] | ||
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] | ||
pub enum PopApiError { | ||
PlaceholderError, | ||
} | ||
|
||
impl ink::env::chain_extension::FromStatusCode for PopApiError { | ||
fn from_status_code(status_code: u32) -> core::result::Result<(), Self> { | ||
match status_code { | ||
0 => Ok(()), | ||
1 => Err(Self::PlaceholderError), | ||
_ => panic!("encountered unknown status code"), | ||
} | ||
} | ||
} | ||
|
||
impl From<scale::Error> for PopApiError { | ||
fn from(_: scale::Error) -> Self { | ||
panic!("encountered unexpected invalid SCALE encoding") | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] | ||
pub enum PopEnv {} | ||
|
||
impl Environment for PopEnv { | ||
const MAX_EVENT_TOPICS: usize = <ink::env::DefaultEnvironment as Environment>::MAX_EVENT_TOPICS; | ||
|
||
type AccountId = <ink::env::DefaultEnvironment as Environment>::AccountId; | ||
type Balance = <ink::env::DefaultEnvironment as Environment>::Balance; | ||
type Hash = <ink::env::DefaultEnvironment as Environment>::Hash; | ||
type BlockNumber = <ink::env::DefaultEnvironment as Environment>::BlockNumber; | ||
type Timestamp = <ink::env::DefaultEnvironment as Environment>::Timestamp; | ||
|
||
type ChainExtension = PopApi; | ||
} | ||
|
||
#[ink::chain_extension] | ||
pub trait PopApi { | ||
type ErrorCode = PopApiError; | ||
|
||
#[ink(extension = 0xfecb)] | ||
#[allow(private_interfaces)] | ||
fn dispatch(call: RuntimeCall) -> crate::Result<Vec<u8>>; | ||
} | ||
|
||
fn call_runtime(call: RuntimeCall) -> Result<Vec<u8>> { | ||
<<PopEnv as Environment>::ChainExtension as ChainExtensionInstance>::instantiate() | ||
.dispatch(call) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pub mod balances; | ||
pub mod nfts; | ||
|
||
#[derive(scale::Encode)] | ||
pub(crate) enum RuntimeCall { | ||
#[codec(index = 50)] | ||
Nfts(nfts::NftCalls), | ||
} |
Oops, something went wrong.