Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext_contract feature in sdk-js #243

Open
exalate-issue-sync bot opened this issue Sep 23, 2022 · 2 comments
Open

ext_contract feature in sdk-js #243

exalate-issue-sync bot opened this issue Sep 23, 2022 · 2 comments
Labels

Comments

@exalate-issue-sync
Copy link

No description provided.

@exalate-issue-sync
Copy link
Author

Bo Yao commented:

it's possible but looks very hacky to implement in JS. Basically, it's a code generation like NearBindgen. But it cannot be a decorator as JS restrict where a decorator can apply, so it must be a function-like "macro". And JS doesn't have macro. Babel can do, but it's going to be magical to user and I'm not sure this is better than Promise.new.functionCall.

@exalate-issue-sync
Copy link
Author

Bo Yao commented:

possible snippet:

import {PromiseOrValue, call, ExtContract, NearBindgen, near, Gas} from 'near-sdk-js';

// Prepaid gas for a single (not inclusive of recursion) factorial call.
const FACTORIAL_CALL_GAS: Gas = 20_000_000_000_000n;

// Prepaid gas for a single factorial_mult call.
const FACTORIAL_MULT_CALL_GAS: Gas = 10_000_000_000_000n;

const ext = ExtContract(class ExtCrossContract{
factorial: (n: number) => PromiseOrValue

;
factorial_mult: (n: number, cur: number) => number;
})

@NearBindgen({})
class ExtCrossContract{
@call({})
factorial(n: number): PromiseOrValue

<number>

{
    if (n &lt;= 1) {
        return 1;
    }
    let accountId = near.currentAccountId();
    let prepaidGas = near.prepaidGas() - FACTORIAL_CALL_GAS;

    return ext.factorial(n-1, accountId, 0, prepaidGas - FACTORIAL_MULT_CALL_GAS)
        .then(ext.factorial_mult(n, accountId, 0, FACTORIAL_MULT_CALL_GAS))
}
@call({privateFunction: true, callbacks: ['cur']})
factorial_mult(n: number, cur: number): number {
    near.log(`Received ${n} and ${cur}`);
    let result = n * cur;
    near.log(`Multiplied ${result}`);
    return result;
}

}

</number>

@ailisp ailisp added v2.0+ and removed v1.0+ labels Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
@ailisp and others