-
Notifications
You must be signed in to change notification settings - Fork 166
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
5 changed files
with
132 additions
and
162 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 |
---|---|---|
@@ -1,39 +1,27 @@ | ||
const commander = require('commander'); | ||
const newClient = require('../grpc/client'); | ||
|
||
commander | ||
.usage(["[OPTIONS] ..."]) | ||
.requiredOption("-a, --address <contract address>", "The address of the destination contract") | ||
.requiredOption("-p, --payload <payload>", "The payload of the wasm message") | ||
.parse(process.argv); | ||
function broadcast(address, payload) { | ||
console.log("Broadcasting message:\n", address, payload); | ||
|
||
const address = commander.opts().address; | ||
if (!address) { | ||
console.error("Address is required"); | ||
process.exit(1); | ||
} | ||
try { | ||
JSON.parse(payload); | ||
} catch (e) { | ||
console.error("Payload is not valid JSON"); | ||
process.exit(1); | ||
} | ||
|
||
const payload = commander.opts().payload; | ||
if (!payload) { | ||
console.error("Payload is required"); | ||
process.exit(1); | ||
} | ||
try { | ||
JSON.parse(payload); | ||
} catch (e) { | ||
console.error("Payload is not valid JSON"); | ||
process.exit(1); | ||
const client = newClient(); | ||
const broadcastRequest = { address, payload: Buffer.from(payload) }; | ||
response = client.Broadcast(broadcastRequest, (err, response) => { | ||
if (err) { | ||
console.error("Error", err); | ||
} else { | ||
console.log("Message sent for broadcast"); | ||
process.exit(0); | ||
} | ||
}); | ||
} | ||
|
||
console.log("Broadcasting message:\n", address, payload); | ||
|
||
const client = newClient(); | ||
const broadcastRequest = { address, payload: Buffer.from(payload) }; | ||
response = client.Broadcast(broadcastRequest, (err, response) => { | ||
if (err) { | ||
console.error("Error", err); | ||
} else { | ||
console.log("Message sent for broadcast"); | ||
process.exit(0); | ||
} | ||
}); | ||
module.exports = { | ||
broadcast, | ||
}; |
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,25 +1,25 @@ | ||
const commander = require('commander'); | ||
const newClient = require('../grpc/client'); | ||
|
||
commander | ||
.usage(["[OPTIONS] ..."]) | ||
.requiredOption("--hash, <payload hash>", "The hash of the payload") | ||
.parse(process.argv); | ||
function getPayload(hash) { | ||
console.log("Getting payload for payload hash", hash); | ||
|
||
const hash = commander.opts().hash.replace('0x', ''); | ||
hash = hash.replace('0x', ''); | ||
|
||
console.log("Getting payload for payload hash", hash); | ||
const client = newClient(); | ||
const getPayloadHashRequest = { hash: Buffer.from(hash, 'hex') }; | ||
response = client.GetPayload(getPayloadHashRequest, (err, response) => { | ||
if (err) { | ||
console.error("Error", err); | ||
process.exit(1) | ||
} | ||
|
||
const client = newClient(); | ||
const getPayloadHashRequest = { hash: Buffer.from(hash, 'hex') }; | ||
response = client.GetPayload(getPayloadHashRequest, (err, response) => { | ||
if (err) { | ||
console.error("Error", err); | ||
process.exit(1) | ||
} | ||
if (response) { | ||
console.log("Payload:\n" + response.payload.toString('hex')); | ||
process.exit(0) | ||
} | ||
}); | ||
} | ||
|
||
if (response) { | ||
console.log("Payload:\n" + response.payload.toString('hex')); | ||
process.exit(0) | ||
} | ||
}); | ||
module.exports = { | ||
getPayload, | ||
}; |
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,34 +1,28 @@ | ||
const commander = require('commander'); | ||
const newClient = require('../grpc/client'); | ||
|
||
commander | ||
.usage(["[OPTIONS] ..."]) | ||
.requiredOption("-c, --chain <chain>", "The chain to subscribe to") | ||
.option("-s, --start-height <start height>", "The block height to start from (0 = latest)", parseInt, 0) | ||
.parse(process.argv); | ||
function subscribe_to_approvals(chain, startHeight) { | ||
console.log("Subscribing to approvals starting from block:", startHeight == 0 ? "latest" : startHeight, "on chain:", chain); | ||
|
||
const options = commander.opts(); | ||
const client = newClient(); | ||
|
||
const chain = options.chain; | ||
const startHeight = options.startHeight; | ||
const call = client.SubscribeToApprovals({ startHeight: startHeight, chains: [chain] }); | ||
call.on('data', (response) => { | ||
console.log("chain:", response.chain); | ||
console.log("block height:", response.blockHeight.toString()); | ||
console.log("execute data:", response.executeData.toString('hex')); | ||
console.log("---"); | ||
}); | ||
call.on('end', () => { | ||
console.log("End"); | ||
}); | ||
call.on('error', (e) => { | ||
console.log("Error", e); | ||
}); | ||
call.on('status', (status) => { | ||
console.log("Status", status); | ||
}); | ||
} | ||
|
||
console.log("Subscribing to approvals starting from block:", startHeight == 0 ? "latest" : startHeight, "on chain:", chain); | ||
|
||
const client = newClient(); | ||
|
||
const call = client.SubscribeToApprovals({ startHeight: startHeight, chains: [chain] }); | ||
call.on('data', (response) => { | ||
console.log("chain:", response.chain); | ||
console.log("block height:", response.blockHeight.toString()); | ||
console.log("execute data:", response.executeData.toString('hex')); | ||
console.log("---"); | ||
}); | ||
call.on('end', () => { | ||
console.log("End"); | ||
}); | ||
call.on('error', (e) => { | ||
console.log("Error", e); | ||
}); | ||
call.on('status', (status) => { | ||
console.log("Status", status); | ||
}); | ||
module.exports = { | ||
subscribe_to_approvals, | ||
}; |
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,26 +1,24 @@ | ||
const commander = require('commander'); | ||
const newClient = require('../grpc/client'); | ||
|
||
commander | ||
.usage(["[OPTIONS] ..."]) | ||
.option("-s, --start-height <start height>", "The block height to start from (0 = latest)", parseInt, 0) | ||
.parse(process.argv); | ||
function subscribe_to_wasm_events(startHeight) { | ||
console.log("Subscribing to events starting from block:", startHeight == 0 ? "latest" : startHeight); | ||
|
||
startHeight = commander.opts().startHeight; | ||
const client = newClient(); | ||
const call = client.SubscribeToWasmEvents({ startHeight: startHeight }); | ||
call.on('data', (response) => { | ||
console.log("Event:", response); | ||
}); | ||
call.on('end', () => { | ||
console.log("End"); | ||
}); | ||
call.on('error', (e) => { | ||
console.log("Error", e); | ||
}); | ||
call.on('status', (status) => { | ||
console.log("Status", status); | ||
}); | ||
} | ||
|
||
console.log("Subscribing to events starting from block:", startHeight == 0 ? "latest" : startHeight); | ||
|
||
const client = newClient(); | ||
const call = client.SubscribeToWasmEvents({ startHeight: startHeight }); | ||
call.on('data', (response) => { | ||
console.log("Event:", response); | ||
}); | ||
call.on('end', () => { | ||
console.log("End"); | ||
}); | ||
call.on('error', (e) => { | ||
console.log("Error", e); | ||
}); | ||
call.on('status', (status) => { | ||
console.log("Status", status); | ||
}); | ||
module.exports = { | ||
subscribe_to_wasm_events, | ||
}; |
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,64 +1,54 @@ | ||
const commander = require('commander'); | ||
const newClient = require('../grpc/client'); | ||
|
||
commander | ||
.usage(["[OPTIONS] ..."]) | ||
.requiredOption("-i, --id <transaction id>", "The id of the transaction (txHash:logIndex)") | ||
.requiredOption("--source-chain <source chain>", "The source chain") | ||
.requiredOption("--source-address <source address>", "The source address") | ||
.requiredOption("--destination-chain <destination chain>", "The destination chain") | ||
.requiredOption("--destination-address <destination address>", "The destination address") | ||
.requiredOption("--payload <payload>", "The GMP payload in hex") | ||
.parse(process.argv); | ||
function verify(id, sourceChain, sourceAddress, destinationChain, destinationAddress, payload) { | ||
console.log("Verifying message with id, sourceChain, sourceAddress, destinationChain, destinationAddress, and payload:", id, sourceChain, sourceAddress, destinationChain, destinationAddress, payload); | ||
|
||
const options = commander.opts(); | ||
|
||
const id = options.id; | ||
if (id.split(':').length != 2) { | ||
console.error("Invalid transaction id. Expected format: txHash:logIndex"); | ||
process.exit(1); | ||
} | ||
const sourceChain = options.sourceChain; | ||
const sourceAddress = options.sourceAddress; | ||
const destinationChain = options.destinationChain; | ||
const destinationAddress = options.destinationAddress; | ||
const payload = options.payload.replace('0x', ''); | ||
|
||
request = { | ||
message: { | ||
id: id, | ||
sourceChain: sourceChain, | ||
sourceAddress: sourceAddress, | ||
destinationChain: destinationChain, | ||
destinationAddress: destinationAddress, | ||
payload: Buffer.from(payload, 'hex'), | ||
}, | ||
}; | ||
|
||
const client = newClient(); | ||
const verifyStream = client.Verify(); | ||
|
||
console.log("Verifying message:", request); | ||
|
||
verifyStream.on('data', function (response) { | ||
if (response.error) { | ||
console.error('Error:', response.error); | ||
} else { | ||
console.log('Success verification for', response.message.id); | ||
process.exit(0); | ||
if (id.split(':').length != 2) { | ||
console.error("Invalid transaction id. Expected format: txHash:logIndex"); | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
verifyStream.on('end', function () { | ||
console.log('Server has completed sending responses.'); | ||
}); | ||
|
||
verifyStream.on('error', function (e) { | ||
console.error('Error: ', e); | ||
}); | ||
|
||
verifyStream.on('status', function (status) { | ||
console.log('Status: ', status); | ||
}); | ||
payload = payload.replace('0x', ''); | ||
|
||
request = { | ||
message: { | ||
id: id, | ||
sourceChain: sourceChain, | ||
sourceAddress: sourceAddress, | ||
destinationChain: destinationChain, | ||
destinationAddress: destinationAddress, | ||
payload: Buffer.from(payload, 'hex'), | ||
}, | ||
}; | ||
|
||
const client = newClient(); | ||
const verifyStream = client.Verify(); | ||
|
||
console.log("Verifying message:", request); | ||
|
||
verifyStream.on('data', function (response) { | ||
if (response.error) { | ||
console.error('Error:', response.error); | ||
} else { | ||
console.log('Success verification for', response.message.id); | ||
process.exit(0); | ||
} | ||
}); | ||
|
||
verifyStream.on('end', function () { | ||
console.log('Server has completed sending responses.'); | ||
}); | ||
|
||
verifyStream.on('error', function (e) { | ||
console.error('Error: ', e); | ||
}); | ||
|
||
verifyStream.on('status', function (status) { | ||
console.log('Status: ', status); | ||
}); | ||
|
||
verifyStream.write(request); | ||
} | ||
|
||
verifyStream.write(request); | ||
module.exports = { | ||
verify, | ||
}; |