Skip to content

Commit

Permalink
quick spike
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx authored and jac18281828 committed Nov 8, 2023
1 parent d903888 commit b893dfa
Show file tree
Hide file tree
Showing 12 changed files with 1,660 additions and 715 deletions.
1,513 changes: 798 additions & 715 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"xmtp_proto",
"xmtp_v2",
"xmtp_mls",
"evm_contracts"
]

exclude = [
Expand Down
35 changes: 35 additions & 0 deletions evm_contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "evm_contracts"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib", "rlib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ethers = { version = "2.0", features = [ "ws", "abigen" ]}
serde = "1.0"
serde_json = "1.0"
serde-wasm-bindgen = "0.6.1"
hex = "0.4"
wasm-bindgen-futures = "0.4"
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
log = "0.4.20"
tracing = "0.1.40"
tracing-subscriber = "0.3.17"
tracing-wasm = "0.2.1"
anyhow = "1.0.75"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }

# needed to enable the "js" feature for compatibility with wasm,
# see https://docs.rs/getrandom/#webassembly-support
getrandom = { version = "0.2", features = ["js"] }

[dev-dependencies]
wasm-bindgen-test = "0.3.6"
3 changes: 3 additions & 0 deletions evm_contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Quick Example of interacting with did:eth contract in wasm

copy of ethers-rs example with some small modifications
40 changes: 40 additions & 0 deletions evm_contracts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>DID Registry</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
<style>
#transactionReceipt {
padding: 10px 20px;
margin-top: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}
#spinner {
margin-top: 10px;
}
</style>
</head>
<body>
<h1> Did Registry Example </h1>
<div id="loading" style="display: none;">
<div id="spinner" class="spinner-border text-primary" role="status"></div>
<div id="spinnerText"></div>
</div>
<div>
<input type="text" id="attributeInput" placeholder="Enter attribute value"></input>
<button id="setAttributeButton">Set Attribute</button>
</div>

<div>
<h5> Transaction Receipt </h5>
<p id = "transactionReceipt">


</p>
</div>

<script src="index.js" defer></script>
</body>
</html>
50 changes: 50 additions & 0 deletions evm_contracts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Registry, set_logger } from './pkg';

set_logger();
let REGISTRY;

const button = document.getElementById('setAttributeButton');
const spinner = document.getElementById('loading');
const transactionReceipt = document.getElementById('transactionReceipt');
const spinnerText = document.getElementById('spinnerText');
spinner.style.display = 'block';
spinnerText.textContent = "Deploying Contract...";
init_registry();


button.addEventListener('click', async () => {
await setAttributeWithValue();
});

async function setAttributeWithValue() {
if (!REGISTRY) {
console.error("Registry not initialized");
return;
}

const attributeInput = document.getElementById('attributeInput');
try {
const inputValue = attributeInput ? attributeInput.value : '';
console.log("Setting attribute ", inputValue);
spinner.style.display = 'block';
spinnerText.textContent = "Submitting Transaction";
let output = await REGISTRY.set_attribute(inputValue.toString());
spinner.style.display = 'none';
transactionReceipt.textContent = output;
} catch (e) {
console.error("Error setting attribute: ", e);
}
}


async function init_registry() {
if (!REGISTRY) {
try {
REGISTRY = await new Registry();
} catch(e) {
console.error(e);
} finally {
spinner.style.display = 'none';
}
}
}
18 changes: 18 additions & 0 deletions evm_contracts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "did-registry-test",
"license": "MIT OR Apache-2.0",
"private": "true",
"scripts": {
"build": "webpack",
"serve": "webpack-dev-server"
},
"devDependencies": {
"@wasm-tool/wasm-pack-plugin": "^1.6",
"ganache-cli": "^6.12",
"html-webpack-plugin": "^5.5",
"text-encoding": "^0.7",
"webpack": "^5.75",
"webpack-cli": "^5.0",
"webpack-dev-server": "^4.11"
}
}
Loading

0 comments on commit b893dfa

Please sign in to comment.