diff --git a/contract-advanced-rs/README.md b/contract-advanced-rs/README.md index 9a79970..68a1207 100644 --- a/contract-advanced-rs/README.md +++ b/contract-advanced-rs/README.md @@ -20,7 +20,6 @@ This contract presents 3 examples on how to do complex cross-contract calls. Par │ │ └── main.ava.ts │ ├── ava.config.cjs │ └── package.json -├── package.json ├── src # contract's code │ ├── batch_actions.rs │ ├── lib.rs diff --git a/contract-advanced-ts/src/contract.ts b/contract-advanced-ts/src/contract.ts index 9e23cbc..8785d2e 100644 --- a/contract-advanced-ts/src/contract.ts +++ b/contract-advanced-ts/src/contract.ts @@ -63,4 +63,4 @@ export class CrossContractCall { similar_contracts_callback({ number_promises }: { number_promises: number;}): string[] { return internal_similar_contracts_callback(number_promises); } -} +} \ No newline at end of file diff --git a/contract-simple-rs/Cargo.toml b/contract-simple-rs/Cargo.toml index 71cde3b..9d0fbc4 100644 --- a/contract-simple-rs/Cargo.toml +++ b/contract-simple-rs/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "contract" +name = "cross_contract" version = "1.0.0" authors = ["Near Inc "] edition = "2021" diff --git a/contract-simple-rs/README.md b/contract-simple-rs/README.md index 21af5c8..8245b34 100644 --- a/contract-simple-rs/README.md +++ b/contract-simple-rs/README.md @@ -114,7 +114,7 @@ near create-account --useFaucet # Deploy the contract ./build.sh -near deploy contract.wasm init '{"hello_account":"hello.near-example.testnet"}' +near deploy ./target/wasm32-unknown-unknown/release/cross_contract.wasm init '{"hello_account":"hello.near-example.testnet"}' ``` ### CLI: Interacting with the Contract diff --git a/contract-simple-rs/test.sh b/contract-simple-rs/test.sh index ed09f5e..86d6fc8 100755 --- a/contract-simple-rs/test.sh +++ b/contract-simple-rs/test.sh @@ -7,4 +7,4 @@ cargo test ./build.sh cd sandbox-ts npm i -npm run test -- -- "../target/wasm32-unknown-unknown/release/contract.wasm" \ No newline at end of file +npm run test -- -- "../target/wasm32-unknown-unknown/release/cross_contract.wasm" \ No newline at end of file diff --git a/contract-simple-ts/README.md b/contract-simple-ts/README.md index ccd8d79..4deee4a 100644 --- a/contract-simple-ts/README.md +++ b/contract-simple-ts/README.md @@ -12,7 +12,6 @@ The smart contract implements the simplest form of cross-contract calls: it call │ │ └── main.ava.ts │ ├── ava.config.cjs │ └── package.json -├── package.json ├── src # contract's code │ └── contract.ts ├── package.json @@ -93,7 +92,7 @@ near create-account --useFaucet # Deploy the contract yarn build -near deploy contract.wasm init '{"hello_account":"hello.near-example.testnet"}' +near deploy ./build/cross_contract.wasm init '{"hello_account":"hello.near-example.testnet"}' ``` ### CLI: Interacting with the Contract diff --git a/contract-simple-ts/src/contract.ts b/contract-simple-ts/src/contract.ts index 8e655ea..21c3ce6 100644 --- a/contract-simple-ts/src/contract.ts +++ b/contract-simple-ts/src/contract.ts @@ -1,11 +1,4 @@ -import { - NearBindgen, - initialize, - call, - near, - bytes, - NearPromise, -} from "near-sdk-js"; +import { NearBindgen, initialize, call, near, bytes, NearPromise } from "near-sdk-js"; import { AccountId } from "near-sdk-js/lib/types"; const FIVE_TGAS = BigInt("50000000000000"); @@ -18,82 +11,64 @@ class CrossContractCall { @initialize({}) init({ hello_account }: { hello_account: AccountId }) { - this.hello_account = hello_account; + this.hello_account = hello_account } @call({}) query_greeting(): NearPromise { const promise = NearPromise.new(this.hello_account) - .functionCall("get_greeting", NO_ARGS, NO_DEPOSIT, FIVE_TGAS) - .then( - NearPromise.new(near.currentAccountId()).functionCall( - "query_greeting_callback", - NO_ARGS, - NO_DEPOSIT, - FIVE_TGAS - ) - ); - + .functionCall("get_greeting", NO_ARGS, NO_DEPOSIT, FIVE_TGAS) + .then( + NearPromise.new(near.currentAccountId()) + .functionCall("query_greeting_callback", NO_ARGS, NO_DEPOSIT, FIVE_TGAS) + ) + return promise.asReturn(); } - @call({ privateFunction: true }) + @call({privateFunction: true}) query_greeting_callback(): String { - let { result, success } = promiseResult(); + let {result, success} = promiseResult() if (success) { - return result.substring(1, result.length - 1); + return result.substring(1, result.length-1); } else { - near.log("Promise failed..."); - return ""; + near.log("Promise failed...") + return "" } } @call({}) change_greeting({ new_greeting }: { new_greeting: string }): NearPromise { const promise = NearPromise.new(this.hello_account) - .functionCall( - "set_greeting", - JSON.stringify({ greeting: new_greeting }), - NO_DEPOSIT, - FIVE_TGAS - ) - .then( - NearPromise.new(near.currentAccountId()).functionCall( - "change_greeting_callback", - NO_ARGS, - NO_DEPOSIT, - FIVE_TGAS - ) - ); + .functionCall("set_greeting", JSON.stringify({ greeting: new_greeting }), NO_DEPOSIT, FIVE_TGAS) + .then( + NearPromise.new(near.currentAccountId()) + .functionCall("change_greeting_callback", NO_ARGS, NO_DEPOSIT, FIVE_TGAS) + ) return promise.asReturn(); } - @call({ privateFunction: true }) + @call({privateFunction: true}) change_greeting_callback(): boolean { - let { success } = promiseResult(); + let { success } = promiseResult() if (success) { - near.log(`Success!`); - return true; + near.log(`Success!`) + return true } else { - near.log("Promise failed..."); - return false; + near.log("Promise failed...") + return false } } } -function promiseResult(): { result: string; success: boolean } { +function promiseResult(): {result: string, success: boolean}{ let result, success; - - try { - result = near.promiseResult(0); - success = true; - } catch { - result = undefined; - success = false; - } - - return { result, success }; -} + + try{ result = near.promiseResult(0); success = true } + catch{ result = undefined; success = false } + + return {result, success} +} \ No newline at end of file