Skip to content

Commit

Permalink
impl to #[near]
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Mar 4, 2024
1 parent 48c849a commit 4812418
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion examples/adder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct DoublePair {
#[near(serializers=[borsh, json], contract_state)]
pub struct Adder {}

#[near(contract_state)]
#[near]
impl Adder {
/// Adds two pairs point-wise.
pub fn add(&self, a: Pair, b: Pair) -> Pair {
Expand Down
2 changes: 1 addition & 1 deletion examples/callback-results/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const A_VALUE: u8 = 8;
#[near(contract_state)]
pub struct Callback;

#[near(contract_state)]
#[near]
impl Callback {
/// Call functions a, b, and c asynchronously and handle results with `handle_callbacks`.
pub fn call_all(fail_b: bool, c_value: u8, d_value: u8) -> Promise {
Expand Down
2 changes: 1 addition & 1 deletion examples/cross-contract-calls/high-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_sdk::{log, near, PromiseOrValue};
#[near(contract_state)]
pub struct CrossContract {}

#[near(contract_state)]
#[near]
impl CrossContract {
pub fn factorial(&self, n: u32) -> PromiseOrValue<u32> {
if n <= 1 {
Expand Down
2 changes: 1 addition & 1 deletion examples/cross-contract-calls/low-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const FACTORIAL_MULT_CALL_GAS: Gas = Gas::from_tgas(10);
#[near(contract_state)]
pub struct CrossContract {}

#[near(contract_state)]
#[near]
impl CrossContract {
pub fn factorial(&self, n: u32) {
if n <= 1 {
Expand Down
2 changes: 1 addition & 1 deletion examples/factory-contract/high-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait ExtStatusMessage {
fn get_status(&self, account_id: AccountId) -> Option<String>;
}

#[near(contract_state)]
#[near]
impl FactoryContract {
pub fn deploy_status_message(&self, account_id: AccountId, amount: NearToken) {
Promise::new(account_id)
Expand Down
2 changes: 1 addition & 1 deletion examples/factory-contract/low-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const SINGLE_CALL_GAS: Gas = Gas::from_tgas(20);
#[near(contract_state)]
pub struct FactoryContract {}

#[near(contract_state)]
#[near]
impl FactoryContract {
pub fn deploy_status_message(&self, account_id: AccountId, amount: U128) {
let promise_idx = env::promise_batch_create(&account_id);
Expand Down
10 changes: 5 additions & 5 deletions examples/fungible-token/ft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum StorageKey {
Metadata,
}

#[near(contract_state)]
#[near]
impl Contract {
/// Initializes the contract with the given total supply owned by the given `owner_id` with
/// default metadata (for example purposes only).
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Contract {
}
}

#[near(contract_state)]
#[near]
impl FungibleTokenCore for Contract {
#[payable]
fn ft_transfer(&mut self, receiver_id: AccountId, amount: U128, memo: Option<String>) {
Expand All @@ -119,7 +119,7 @@ impl FungibleTokenCore for Contract {
}
}

#[near(contract_state)]
#[near]
impl FungibleTokenResolver for Contract {
#[private]
fn ft_resolve_transfer(
Expand All @@ -137,7 +137,7 @@ impl FungibleTokenResolver for Contract {
}
}

#[near(contract_state)]
#[near]
impl StorageManagement for Contract {
#[payable]
fn storage_deposit(
Expand Down Expand Up @@ -173,7 +173,7 @@ impl StorageManagement for Contract {
}
}

#[near(contract_state)]
#[near]
impl FungibleTokenMetadataProvider for Contract {
fn ft_metadata(&self) -> FungibleTokenMetadata {
self.metadata.get().unwrap()
Expand Down
6 changes: 3 additions & 3 deletions examples/fungible-token/test-contract-defi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait ValueReturnTrait {
fn value_please(&self, amount_to_return: String) -> PromiseOrValue<U128>;
}

#[near(contract_state)]
#[near]
impl DeFi {
#[init]
pub fn new(fungible_token_account_id: AccountId) -> Self {
Expand All @@ -29,7 +29,7 @@ impl DeFi {
}
}

#[near(contract_state)]
#[near]
impl FungibleTokenReceiver for DeFi {
/// If given `msg: "take-my-money", immediately returns U128::From(0)
/// Otherwise, makes a cross-contract call to own `value_please` function, passing `msg`
Expand Down Expand Up @@ -60,7 +60,7 @@ impl FungibleTokenReceiver for DeFi {
}
}

#[near(contract_state)]
#[near]
impl ValueReturnTrait for DeFi {
fn value_please(&self, amount_to_return: String) -> PromiseOrValue<U128> {
log!("in value_please, amount_to_return = {}", amount_to_return);
Expand Down
4 changes: 2 additions & 2 deletions examples/lockable-fungible-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Account {
}

#[derive(PanicOnDefault)]
#[near(contract_state)]
#[near]
pub struct FunToken {
/// AccountID -> Account details.
pub accounts: UnorderedMap<AccountId, Account>,
Expand All @@ -55,7 +55,7 @@ pub struct FunToken {
pub total_supply: Balance,
}

#[near(contract_state)]
#[near]
impl FunToken {
#[init]
#[handle_result]
Expand Down
8 changes: 2 additions & 6 deletions examples/mission-control/src/mission_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ use near_sdk::env;
use std::collections::HashMap;
use near_sdk::near;

// #[near(contract_state)]
// #[derive(Serialize, Deserialize, BorshDeserialize, BorshSerialize)]
// #[serde(crate = "near_sdk::serde")]
// #[borsh(crate = "near_sdk::borsh")]

#[near(serializers=[json, borsh], contract_state)]
pub struct MissionControl {
account: Account,
agents: HashMap<AccountId, Agent>,
rates: HashMap<Exchange, Rate>,
}

// #[near]
#[near(contract_state)]
#[near]
impl MissionControl {
pub fn add_agent(&mut self) {
let account_id = env::signer_account_id();
Expand Down
12 changes: 6 additions & 6 deletions examples/non-fungible-token/nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ enum StorageKey {
Approval,
}

#[near(contract_state)]
#[near]
impl Contract {
/// Initializes the contract owned by `owner_id` with
/// default metadata (for example purposes only).
Expand Down Expand Up @@ -107,7 +107,7 @@ impl Contract {
}
}

#[near(contract_state)]
#[near]
impl NonFungibleTokenCore for Contract {
#[payable]
fn nft_transfer(
Expand Down Expand Up @@ -137,7 +137,7 @@ impl NonFungibleTokenCore for Contract {
}
}

#[near(contract_state)]
#[near]
impl NonFungibleTokenResolver for Contract {
#[private]
fn nft_resolve_transfer(
Expand All @@ -156,7 +156,7 @@ impl NonFungibleTokenResolver for Contract {
}
}

#[near(contract_state)]
#[near]
impl NonFungibleTokenApproval for Contract {
#[payable]
fn nft_approve(
Expand Down Expand Up @@ -188,7 +188,7 @@ impl NonFungibleTokenApproval for Contract {
}
}

#[near(contract_state)]
#[near]
impl NonFungibleTokenEnumeration for Contract {
fn nft_total_supply(&self) -> U128 {
self.tokens.nft_total_supply()
Expand All @@ -212,7 +212,7 @@ impl NonFungibleTokenEnumeration for Contract {
}
}

#[near(contract_state)]
#[near]
impl NonFungibleTokenMetadataProvider for Contract {
fn nft_metadata(&self) -> NFTContractMetadata {
self.metadata.get().unwrap()
Expand Down
6 changes: 3 additions & 3 deletions examples/non-fungible-token/test-approval-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ trait ValueReturnTrait {
fn ok_go(&self, msg: String) -> PromiseOrValue<String>;
}

#[near(contract_state)]
#[near]
impl ApprovalReceiver {
#[init]
pub fn new(non_fungible_token_account_id: AccountId) -> Self {
Self { non_fungible_token_account_id: non_fungible_token_account_id.into() }
}
}

#[near(contract_state)]
#[near]
impl NonFungibleTokenApprovalReceiver for ApprovalReceiver {
/// Could do anything useful to the approval-receiving contract, such as store the given
/// approval_id for use later when calling the NFT contract. Can also return whatever it wants,
Expand Down Expand Up @@ -68,7 +68,7 @@ impl NonFungibleTokenApprovalReceiver for ApprovalReceiver {
}
}

#[near(contract_state)]
#[near]
impl ValueReturnTrait for ApprovalReceiver {
fn ok_go(&self, msg: String) -> PromiseOrValue<String> {
log!("in ok_go, msg={}", msg);
Expand Down
6 changes: 3 additions & 3 deletions examples/non-fungible-token/test-token-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ trait ValueReturnTrait {
fn ok_go(&self, return_it: bool) -> PromiseOrValue<bool>;
}

#[near(contract_state)]
#[near]
impl TokenReceiver {
#[init]
pub fn new(non_fungible_token_account_id: AccountId) -> Self {
Self { non_fungible_token_account_id }
}
}

#[near(contract_state)]
#[near]
impl NonFungibleTokenReceiver for TokenReceiver {
/// Returns true if token should be returned to `sender_id`
/// Four supported `msg`s:
Expand Down Expand Up @@ -79,7 +79,7 @@ impl NonFungibleTokenReceiver for TokenReceiver {
}
}

#[near(contract_state)]
#[near]
impl ValueReturnTrait for TokenReceiver {
fn ok_go(&self, return_it: bool) -> PromiseOrValue<bool> {
log!("in ok_go, return_it={}", return_it);
Expand Down
2 changes: 1 addition & 1 deletion examples/status-message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Default for StatusMessage {
}
}

#[near(contract_state)]
#[near]
impl StatusMessage {
#[payable]
pub fn set_status(&mut self, message: String) {
Expand Down
2 changes: 1 addition & 1 deletion examples/test-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl Default for TestContract {
}
}

#[near(contract_state)]
#[near]
impl TestContract {
#[init]
pub fn new() -> Self {
Expand Down
2 changes: 1 addition & 1 deletion examples/versioned/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Default for Contract {
}
}

#[near(contract_state)]
#[near]
impl VersionedContract {
#[payable]
pub fn deposit(&mut self) {
Expand Down

0 comments on commit 4812418

Please sign in to comment.