4 releases

0.0.8 Oct 23, 2023
0.0.7 Jun 9, 2023
0.0.5 Mar 13, 2023
0.0.4 Jan 16, 2023

#2239 in Magic Beans

Download history 2/week @ 2024-02-19 6/week @ 2024-02-26 72/week @ 2024-04-01

72 downloads per month

GPL-3.0 license

48KB
913 lines

near-non-transferable-token

Popula Library for Non-transferable Token.

Crates.io version Download Reference Documentation

Example

use near_non_transferable_token::{impl_fungible_token_core, impl_fungible_token_storage};

#[near_bindgen]
impl Contract {
    #[init]
    pub fn new(
        owner_id: AccountId,
        metadata: FungibleTokenMetadata,
    ) -> Self {
        assert!(!env::state_exists(), "Already initialized");
        metadata.assert_valid();
        let mut this = Self {
            token: FungibleToken::new(b"a".to_vec()),
            metadata: LazyOption::new(b"m".to_vec(), Some(&metadata)),
            owner_id,
            white_list: HashSet::new()
        };
        this
    }
}

impl_fungible_token_core!(Contract, token);
impl_fungible_token_storage!(Contract, token);


#[near_bindgen]
impl FungibleTokenMetadataProvider for Contract {
    fn ft_metadata(&self) -> FungibleTokenMetadata {
        self.metadata.get().unwrap()
    }
}

See https://github.com/beepopula/Drip-contract for more details.

Features

Account Book

Separate Balances for different contracts:

#[derive(BorshDeserialize, BorshSerialize)]
pub struct Account {
    pub contract_ids: UnorderedMap<Option<AccountId>, Balance>,
    pub deposit_map: UnorderedMap<AccountId, HashMap<Option<AccountId>, Balance>>  //key: specific community drip
}

NOTES:

  • If the key for contract_ids is None then it represent the sum of Balance.
  • Deposit is a derivative function for proving that you have such balance for only once, preventing infinite proving. And the ownership should remain the same.

Versioning

Semantic Versioning

This crate follows Cargo's semver guidelines.

State breaking changes (low-level serialization format of any data type) will be avoided at all costs. If a change like this were to happen, it would come with a major version and come with a compiler error. If you encounter one that does not, open an issue!

MSRV

The minimum supported Rust version is currently 1.56. There are no guarantees that this will be upheld if a security patch release needs to come in that requires a Rust toolchain increase.

Dependencies

~5MB
~98K SLoC