Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): expose get transaction method | /workflows/cd #105

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wraps/core/polywrap.deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
package: http
uri: $$ipfs_deploy
config:
postUrl: https://wraps.wrapscan.io/r/polywrap/[email protected].0
postUrl: https://wraps.wrapscan.io/r/polywrap/[email protected].1
headers:
- name: Authorization
value: $POLYWRAP_WRAPSCAN_AUTH_HEADER_PROD
6 changes: 6 additions & 0 deletions wraps/core/polywrap.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ type Module implements Utils_Module {
connection: Connection
): BigInt!

# Get a transaction data based in given hash
getTransaction(
hash: String!
connection: Connection
): TxResponse!

# Send an arbitrary JSON-RPC request to the Ethereum node
sendRpc(
# JSON-RPC method to call
Expand Down
14 changes: 14 additions & 0 deletions wraps/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ impl ModuleTrait for Module {
))
}

fn get_transaction(args: wrap::ArgsGetTransaction) -> Result<TxResponse, String> {
let provider = WrapProvider::new(&args.connection);
let transaction = provider.get_transaction(H256::from_str(&args.hash).unwrap());
if let Ok(tx) = transaction {
if let Some(tx) = tx {
Ok(mapping::to_wrap_response(&provider, tx))
} else {
return Err(format!("Transaction with hash {} not found", args.hash));
}
} else {
return Err("Error fetching transaction".to_string());
}
}

fn check_address(args: wrap::ArgsCheckAddress) -> Result<bool, String> {
Ok(match Address::from_str(&args.address) {
Ok(_) => true,
Expand Down
17 changes: 14 additions & 3 deletions wraps/core/tests/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,17 +445,28 @@ describe("Ethereum Wrapper", () => {
expect(response.value.hash).toBeDefined();
})
it("using provider signer", async () => {
const response = await clientWithWeb3Provider.invoke<Schema.TxResponse>({
const response = await clientWithWeb3Provider.invoke<Schema.TxReceipt>({
uri,
method: "sendTransaction",
method: "sendTransactionAndWait",
args: {
tx: { data: contracts.SimpleStorage.bytecode }
}
});

if (!response.ok) throw response.error;
expect(response.value).toBeDefined();
expect(response.value.hash).toBeDefined();
expect(response.value).toBeDefined();

const getTransactionResponse = await clientWithWeb3Provider.invoke<string>({
uri,
method: "getTransaction",
args: {
hash: response.value.transactionHash,
},
});

if (!getTransactionResponse.ok) throw getTransactionResponse.error;
expect(getTransactionResponse.value).toBeDefined();
})
})

Expand Down