-
Notifications
You must be signed in to change notification settings - Fork 24
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
1 parent
d903888
commit b893dfa
Showing
12 changed files
with
1,660 additions
and
715 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ members = [ | |
"xmtp_proto", | ||
"xmtp_v2", | ||
"xmtp_mls", | ||
"evm_contracts" | ||
] | ||
|
||
exclude = [ | ||
|
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,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" |
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,3 @@ | ||
# Quick Example of interacting with did:eth contract in wasm | ||
|
||
copy of ethers-rs example with some small modifications |
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,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> |
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,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'; | ||
} | ||
} | ||
} |
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,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" | ||
} | ||
} |
Oops, something went wrong.