-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add several examples. Prepare 0.1.0-beta.1 (#17)
* Add first examples, use U256 for references. * Add more examples * Add MSRV * Release 0.1.0-beta.1
- Loading branch information
1 parent
3a8e8fa
commit 4e24cc0
Showing
15 changed files
with
595 additions
and
214 deletions.
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 |
---|---|---|
|
@@ -6,20 +6,82 @@ on: | |
pull_request: | ||
branches: | ||
- master | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
clippy: | ||
name: Clippy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Stable with rustfmt and clippy | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
components: rustfmt, clippy | ||
- name: Release build | ||
run: cargo build --release --all-features | ||
- uses: giraffate/clippy-action@v1 | ||
with: | ||
reporter: 'github-pr-review' | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
build: | ||
name: Build with rust ${{matrix.rust}} on ${{matrix.os == 'ubuntu' && 'Linux' || matrix.os == 'macos' && 'macOS' || matrix.os == 'windows' && 'Windows' || '???'}} | ||
runs-on: ${{matrix.os}}-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
rust: | ||
- "1.67.1" # MSRV | ||
- "stable" | ||
- "beta" | ||
- "nightly" | ||
os: [ubuntu, windows, macos] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Stable with rustfmt and clippy | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
components: rustfmt, clippy | ||
toolchain: ${{matrix.rust}} | ||
- name: Release build | ||
run: cargo build --release --all-features | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v3 | ||
- uses: pre-commit/[email protected] | ||
|
||
- name: Install stable toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: stable | ||
|
||
- uses: taiki-e/install-action@v2 | ||
with: | ||
tool: cargo-tarpaulin,cargo-rdme | ||
|
||
- name: Check README is up-to-date | ||
run: cargo rdme --check | ||
|
||
- name: Run tests with coverage | ||
run: RUST_BACKTRACE=1 cargo tarpaulin --out Xml --all-features | ||
|
||
- name: Submit a transaction to chain | ||
run: RUST_BACKTRACE=1 cargo run --example transaction_broadcast --all-features | ||
env: | ||
TEST_TO_ADDRESS: ${{ secrets.TO_ADDRESS }} | ||
TEST_MNEMONIC: ${{ secrets.MNEMONIC }} | ||
|
||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
- name: Archive code coverage results | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: code-coverage-report | ||
path: cobertura.xml |
This file was deleted.
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "thor-devkit" | ||
version = "0.1.0-alpha.1" | ||
version = "0.1.0-beta.1" | ||
authors = ["Stanislav Terliakov <[email protected]>"] | ||
description = "Rust library to aid coding with VeChain, eg. Wallets/Tx/Sign/Verify." | ||
documentation = "https://docs.rs/thor-devkit.rs" | ||
|
@@ -10,6 +10,7 @@ keywords = ["vechain", "crypto", "blockchain", "cryptography"] | |
categories = ["cryptography"] | ||
license = "GPL-3.0" | ||
edition = "2021" | ||
rust-version = "1.67.1" | ||
|
||
# See here for more info: https://blog.rust-lang.org/2020/03/15/docs-rs-opt-into-fewer-targets.html | ||
|
||
|
@@ -40,8 +41,10 @@ serde_with = { version = "^3.4", features = ["hex"], optional = true } | |
version-sync = "0.9.4" | ||
rand = { version = "0.8.5", features = ["getrandom"] } | ||
tokio = { version = "1", features = ["full"] } | ||
bloomfilter = "^1.0" | ||
ethabi = "^18.0" | ||
|
||
[features] | ||
default = ['http'] | ||
# default = ['http'] | ||
serde = ["dep:serde", "dep:serde_json", "dep:serde_with"] | ||
http = ["dep:reqwest", "serde"] |
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,163 @@ | ||
[ | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "_spender", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "approve", | ||
"outputs": [ | ||
{ | ||
"name": "success", | ||
"type": "bool" | ||
} | ||
], | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "totalSupply", | ||
"outputs": [ | ||
{ | ||
"name": "total", | ||
"type": "uint256" | ||
} | ||
], | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "_from", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_to", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transferFrom", | ||
"outputs": [ | ||
{ | ||
"name": "success", | ||
"type": "bool" | ||
} | ||
], | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"name": "_owner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"name": "balance", | ||
"type": "uint256" | ||
} | ||
], | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "_to", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transfer", | ||
"outputs": [ | ||
{ | ||
"name": "success", | ||
"type": "bool" | ||
} | ||
], | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"name": "_owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_spender", | ||
"type": "address" | ||
} | ||
], | ||
"name": "allowance", | ||
"outputs": [ | ||
{ | ||
"name": "remaining", | ||
"type": "uint256" | ||
} | ||
], | ||
"type": "function" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"name": "from", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"name": "to", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Transfer", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"name": "owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"name": "spender", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Approval", | ||
"type": "event" | ||
} | ||
] |
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,49 @@ | ||
//! thor-devkit does not vendor ABI parsing solution, because a good one | ||
//! already exists in wild ([`ethabi`](https://docs.rs/ethabi/latest/ethabi/index.html)). | ||
//! | ||
//! To decode or encode data given a contract ABI and some input data, | ||
//! you can create a contract from JSON ABI specification and process it | ||
//! as necessary. | ||
//! | ||
//! Future version of thor-devkit will likely depend on [`ethabi`] to improve | ||
//! interoperability and enable more smooth experience. | ||
use ethabi::{Contract, Token}; | ||
use std::fs::File; | ||
use thor_devkit::rlp::Bytes; | ||
|
||
fn demo_abi() { | ||
let eip20 = Contract::load(File::open("data/eip20.abi").expect("Must exist")) | ||
.expect("Should be loadable"); | ||
let owner = [0u8; 20]; | ||
let spender = [1u8; 20]; | ||
let inputs = vec![Token::Address(owner.into()), Token::Address(spender.into())]; | ||
let allowance = eip20.function("allowance").expect("Exists"); | ||
println!("Function signature: {}", allowance.signature()); | ||
println!( | ||
"Function short signature: {:02x?}", | ||
allowance.short_signature() | ||
); | ||
let encoded = allowance | ||
.encode_input(&inputs) | ||
.expect("Should be encodable"); | ||
println!( | ||
"Encoded data for allowance call: {:x}", | ||
Bytes::copy_from_slice(&encoded[..]) | ||
); | ||
// To decode, we strip a function signature first: | ||
let decoded = allowance.decode_input(&encoded[4..]).expect("Should parse"); | ||
assert_eq!(decoded, inputs); | ||
|
||
let decoded_out = allowance.decode_output(&[0x01; 32]).expect("Should parse"); | ||
assert_eq!(decoded_out, vec![Token::Uint([0x01; 32].into())]) | ||
} | ||
|
||
#[test] | ||
fn test_run() { | ||
demo_abi(); | ||
} | ||
|
||
fn main() { | ||
demo_abi(); | ||
} |
Oops, something went wrong.