Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
664 changes: 401 additions & 263 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion chain/core/src/types/flags/esdt_local_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ESDT_ROLE_SET_NEW_URI: &str = "ESDTRoleSetNewURI";
const ESDT_ROLE_MODIFY_ROYALTIES: &str = "ESDTRoleModifyRoyalties";
const ESDT_ROLE_MODIFY_CREATOR: &str = "ESDTRoleModifyCreator";
const ESDT_ROLE_NFT_RECREATE: &str = "ESDTRoleNFTRecreate";
const ESDT_ROLE_TRANSFER: &str = "ESDTTransferRole";

#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug, Copy)]
pub enum EsdtLocalRole {
Expand All @@ -31,6 +32,7 @@ pub enum EsdtLocalRole {
ModifyRoyalties,
ModifyCreator,
SetNewUri,
Transfer,
}

impl EsdtLocalRole {
Expand All @@ -48,6 +50,7 @@ impl EsdtLocalRole {
Self::ModifyCreator => 9,
Self::ModifyRoyalties => 10,
Self::SetNewUri => 11,
Self::Transfer => 12,
}
}

Expand All @@ -69,6 +72,7 @@ impl EsdtLocalRole {
Self::ModifyRoyalties => ESDT_ROLE_MODIFY_ROYALTIES,
Self::ModifyCreator => ESDT_ROLE_MODIFY_CREATOR,
Self::SetNewUri => ESDT_ROLE_SET_NEW_URI,
Self::Transfer => ESDT_ROLE_TRANSFER,
}
}

Expand All @@ -86,13 +90,14 @@ impl EsdtLocalRole {
Self::ModifyRoyalties => EsdtLocalRoleFlags::MODIFY_ROYALTIES,
Self::ModifyCreator => EsdtLocalRoleFlags::MODIFY_CREATOR,
Self::SetNewUri => EsdtLocalRoleFlags::SET_NEW_URI,
Self::Transfer => EsdtLocalRoleFlags::TRANSFER,
}
}
}

// TODO: can be done with macros, but I didn't find a public library that does it and is no_std
// we can implement it, it's easy
const ALL_ROLES: [EsdtLocalRole; 11] = [
const ALL_ROLES: [EsdtLocalRole; 12] = [
EsdtLocalRole::Mint,
EsdtLocalRole::Burn,
EsdtLocalRole::NftCreate,
Expand All @@ -104,6 +109,7 @@ const ALL_ROLES: [EsdtLocalRole; 11] = [
EsdtLocalRole::ModifyRoyalties,
EsdtLocalRole::ModifyCreator,
EsdtLocalRole::SetNewUri,
EsdtLocalRole::Transfer,
];

impl EsdtLocalRole {
Expand All @@ -127,6 +133,7 @@ impl From<u16> for EsdtLocalRole {
9 => Self::ModifyRoyalties,
10 => Self::ModifyCreator,
11 => Self::SetNewUri,
12 => Self::Transfer,
_ => Self::None,
}
}
Expand Down Expand Up @@ -157,6 +164,8 @@ impl<'a> From<&'a [u8]> for EsdtLocalRole {
Self::ModifyCreator
} else if byte_slice == ESDT_ROLE_SET_NEW_URI.as_bytes() {
Self::SetNewUri
} else if byte_slice == ESDT_ROLE_TRANSFER.as_bytes() {
Self::Transfer
} else {
Self::None
}
Expand Down
2 changes: 2 additions & 0 deletions chain/core/src/types/flags/esdt_local_role_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ bitflags! {
const MODIFY_CREATOR = 0b00000001_00000000;
const MODIFY_ROYALTIES = 0b00000010_00000000;
const SET_NEW_URI = 0b00000100_00000000;
//TODO: check this flag after barnard
const TRANSFER = 0b00001000_00000000;
}
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/examples/crowdfunding-esdt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ publish = false
path = "src/crowdfunding_esdt.rs"

[dependencies.multiversx-sc]
version = "0.56.1"
path = "../../../framework/base"
git = "https://github.com/multiversx/mx-sdk-rs"
rev = "3050fab"

[dev-dependencies.multiversx-sc-scenario]
version = "0.56.1"
path = "../../../framework/scenario"
git = "https://github.com/multiversx/mx-sdk-rs"
rev = "3050fab"

[dev-dependencies]
num-bigint = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions contracts/examples/crowdfunding-esdt/meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ publish = false
path = ".."

[dependencies.multiversx-sc-meta-lib]
version = "0.56.1"
path = "../../../../framework/meta-lib"
git = "https://github.com/multiversx/mx-sdk-rs"
rev = "3050fab"
default-features = false
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,20 @@ where
tx.original_result()
}

/// This function can be called to retrieve the special roles of a specific token.
pub fn get_special_roles<Arg0: ProxyArg<TokenIdentifier<Env::Api>>>(
self,
token_identifier: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
let tx = self
.wrapped_tx
.payment(NotPayable)
.raw_call("getSpecialRoles")
.argument(&token_identifier);

tx.original_result()
}

/// This function can be called only if canSetSpecialRoles was set to true.
/// The metachain system SC will evaluate the arguments and call “ESDTUnsetRole@tokenId@listOfRoles” for the given address.
/// This will be actually a cross shard call.
Expand Down
18 changes: 18 additions & 0 deletions tools/interactor-system-func-calls/src/system_sc_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,24 @@ impl SysFuncCallsInteract {
.await;
}

pub async fn get_roles(&mut self, token_id: &[u8]) {
println!("Retrieving special roles for {token_id:?}");

let result = self
.interactor
.tx()
.from(&self.wallet_address)
.to(ESDTSystemSCAddress)
.gas(100_000_000u64)
.typed(ESDTSystemSCProxy)
.get_special_roles(TokenIdentifier::from(token_id))
.returns(ReturnsRawResult)
.run()
.await;

println!("raw result for roles {result:?}");
}

pub async fn change_to_dynamic(&mut self, token_id: &[u8]) {
println!("Changing the following token {token_id:?} to dynamic...");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,31 @@ async fn modify_creator() {
.modify_creator(dynamic_nft_token_id.as_bytes(), nonce)
.await;
}

#[tokio::test]
#[ignore = "run on demand"]
async fn transfer_role() {
let mut interact = SysFuncCallsInteract::init(Config::load_config()).await;

// issue dynamic NFT
let dynamic_nft_token_id = interact
.issue_dynamic_token(
RustBigUint::from(ISSUE_COST),
b"TESTNFT",
b"TEST",
EsdtTokenType::DynamicNFT,
0usize,
)
.await;

// set roles
interact
.set_roles(
dynamic_nft_token_id.as_bytes(),
vec![EsdtLocalRole::Transfer],
)
.await;

// get roles
interact.get_roles(dynamic_nft_token_id.as_bytes()).await;
}
Loading