This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule StarknetExplorer.Pedersen do | ||
use Rustler, otp_app: :starknet_explorer, crate: "pedersen" | ||
# @spec decode(binary, atom) :: binary | ||
# def decode(_b64, _opt \\ :standard), do: error() | ||
|
||
# @spec encode(binary, atom) :: binary | ||
# def encode(_s, _opt \\ :standard), do: error() | ||
|
||
# defp _error(), do: :erlang.nif_error(:nif_not_loaded) | ||
|
||
# fn caclulate_contract_hash<'a>(salt: String, class_hash: String, constructor_calldata: Vec<String>, deployer_address: String) -> NifResult<String> { | ||
def calculate_contract_address(salt, class_hash, constructor_calldata, deployer_address), | ||
Check warning on line 12 in lib/starknet_explorer/pedersen.ex GitHub Actions / Build and test (1.15, 25)
Check warning on line 12 in lib/starknet_explorer/pedersen.ex GitHub Actions / Build and test (1.15, 25)
Check warning on line 12 in lib/starknet_explorer/pedersen.ex GitHub Actions / Build and test (1.15, 25)
|
||
do: :erlang.nif_error(:nif_not_loaded) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[target.'cfg(target_os = "macos")'] | ||
rustflags = [ | ||
"-C", "link-arg=-undefined", | ||
"-C", "link-arg=dynamic_lookup", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
/Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "pedersen" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rustler = "0.29" | ||
starknet_in_rust = { git = "https://github.com/lambdaclass/starknet_in_rust", version="0.4.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
extern crate rustler; | ||
use rustler::{NifResult, Error}; | ||
use starknet_in_rust::{hash_utils::calculate_contract_address, felt::{Felt252, felt_str}, utils::Address}; | ||
|
||
rustler::init!("Elixir.Pedersen", | ||
[caclulate_contract_hash] | ||
); | ||
|
||
#[rustler::nif] | ||
fn caclulate_contract_hash<'a>(salt: String, class_hash: String, constructor_calldata: Vec<String>, deployer_address: String) -> NifResult<String> { | ||
let salt = felt_str!(salt.strip_prefix("0x").unwrap_or(&salt), 16); | ||
let class_hash: Felt252 = felt_str!(class_hash.strip_prefix("0x").unwrap_or(&class_hash), 16); | ||
let constructor_calldata: Vec<Felt252> = constructor_calldata.iter().map(|f| felt_str!(f.strip_prefix("0x").unwrap_or(&f), 16)).collect(); | ||
let deployer_address = felt_str!(deployer_address.strip_prefix("0x").unwrap_or(&deployer_address), 16); | ||
|
||
let contract_address = calculate_contract_address(&salt, &class_hash, &constructor_calldata, Address(deployer_address)); | ||
|
||
match contract_address { | ||
Ok(v) => NifResult::Ok(v.to_str_radix(16)), | ||
Err(err) => NifResult::Err(Error::Term(Box::new(format!("Error calculating contract address: {}", err)))) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
priv/repo/migrations/20230926222639_create_internal_calls.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule StarknetExplorer.Repo.Migrations.CreateInternalCalls do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:internal_calls) do | ||
add :transaction_hash, :string | ||
add :type, :string | ||
add :function_selector, :string | ||
add :contract_address, :string | ||
add :calldata, {:array, :string} | ||
|
||
timestamps() | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
rustlers: [ | ||
[ | ||
name: "pedersen", | ||
path: "native/pedersen", | ||
cargo_target: "release" | ||
] | ||
] | ||
] |