move icon indicating copy to clipboard operation
move copied to clipboard

[Feature Request] Any function can be an entry point-- support in forthcoming Solana transaction interface.

Open nvjle opened this issue 2 years ago • 4 comments

Currently for compiler bring-up/debug, we only support a single entry point specified as the script main.

In Move, however, any module function can be an entry point. This is specified via the entry keyword on the function definition, and this is the common way things are done in Move-based chains such as Aptos.

Moreover, client-callable entry functions can take any argument the user wishes, making for a natural programming model. Consider the Aptos coin module:

/// This module provides the foundation for typesafe Coins.
module aptos_framework::coin {
    ...
   /// Transfers `amount` of coins `CoinType` from `from` to `to`.
    public entry fun transfer<CoinType>(
        from: &signer,
        to: address,
        amount: u64,
    ) acquires CoinStore {
        let coin = withdraw<CoinType>(from, amount);
        deposit(to, coin);
    }
 ...

There is no script-- the user client can directly invoke coin::transfer, for example:

let txn_hash = coin_client
    .transfer(&mut alice, bob.address(), 1_000, None)
    .await
    .context("Failed to submit transaction to transfer coins")?; 

The ask is to have a similarly flexible and natural programming model.

  • [ ] Support multiple entry points.
    • [x] Concrete #182
    • [ ] Generic #180
    • [x] Multiple modules #369
  • [x] Support a shim/interface between the Solana fixed incoming parameter bundle and an arbitrary entry function.

See, e.g., https://github.com/aptos-labs/aptos-core/tree/main/sdk/src/transaction_builder.rs and https://github.com/aptos-labs/aptos-core/tree/main/sdk/src/coin_client.rs for some ideas.

Aptos core: https://github.com/aptos-labs/aptos-core

nvjle avatar May 19 '23 19:05 nvjle

I'd like to assign this issue to myself, unless someone is already making progress on this.

dmakarov avatar Jun 01 '23 21:06 dmakarov

I'd like to assign this issue to myself, unless someone is already making progress on this.

Please do :+1:

nvjle avatar Jun 01 '23 22:06 nvjle

Partial implementation is added in #251

dmakarov avatar Jul 26 '23 13:07 dmakarov

#260, #266, and #273 resolve this for now. Updates will be necessary when Solana Runtime support for Move is finalized.

dmakarov avatar Aug 16 '23 18:08 dmakarov