0xMiden / 0xMiden/rust-sdk

Fetch public account code automatically (from node?)

Aberta
#1,155 10 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Rust
Estrelas
78
Forks
129
Merge médio
4d 14h
PRs com merge (30d)
52

Descrição

The way we currently interact (e.g. via a note/tx script) with an account that has custom code:
1. We locally prepare `account_code`. For an already-deployed contract, we specifically need its MASM code (locally?), which already sounds cumbersome,
2. We need to create a library out of that account code,
3. We need to setup a custom assembler with the library we just created, otherwise the tx/note script won't "understand" what to call.

It looks like:
```rust
let assembler: Assembler = TransactionKernel::assembler();
let source_manager = Arc::new(DefaultSourceManager::default());
let module = Module::parser(ModuleKind::Library).parse_str(
LibraryPath::new("external_contract::counter_contract").unwrap(),
account_code, // <------- need the contract code locally
&source_manager,
)?;
let library = assembler.clone().assemble_library([module])?;

// still setting up the assembler...
let assembler = TransactionKernel::assembler()
.with_dynamic_library(library)
.unwrap();

// and only then can we build the note script:
NoteBuilder::new(native_account.id(), client.rng())
.code(
"use.external_contract::counter_contract
begin
call.counter_contract::increment_count
end",
)
.tag(NoteTag::from_account_id(network_account.id()).into())
.build(&assembler)
.unwrap(),
```

While there might not be an easier way around step 1. for private contracts, I feel like we should allow for executing against public & network accounts in an easier fashion.

Perhaps there is an easier way to do all of this above? @Dominik1999 @bobbinth

If not, then we should probably re-think the DevEx here. Ideally, I'd want to build the script with a simple call like:
```rust
// for a public/network `Account`:
let account_code = client.fetch_code(account_id);
let tx_script = TransactionScript::against_public_contract(script_code, account_code)?;
```

I imagine the best way to go about this is for the node to "serve" the account code to the `client`, who could easily verify that the provided code matches the onchain commitment.
An alternative would be to have a public repository of smart contract codes which the users can query, but this requires an external service.

_Originally posted by @mmagician in https://github.com/0xMiden/project-template/pull/4#discussion_r2250087768_

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.