-
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.
chore(amplifier): tidy up commands and update commander lib (#174)
* chore: update commander version * chore: create separate index.js as an entrypoint for all commands * chore: export commands functions * chore: rename index.js -> amplifier.js * chore: update docs
- Loading branch information
1 parent
16f0278
commit 952412f
Showing
9 changed files
with
200 additions
and
176 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
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,52 @@ | ||
const commander = require('commander'); | ||
const { broadcast } = require('./endpoints/broadcast.js'); | ||
const { getPayload } = require('./endpoints/get-payload.js'); | ||
const { subscribe_to_approvals } = require('./endpoints/subscribe-to-approvals.js'); | ||
const { subscribe_to_wasm_events } = require('./endpoints/subscribe-to-wasm-events.js'); | ||
const { verify } = require('./endpoints/verify.js'); | ||
|
||
const program = new commander.Command(); | ||
|
||
program | ||
.command('broadcast') | ||
.requiredOption('-a, --address <contract address>', 'The address of the destination contract') | ||
.requiredOption("-p, --payload <payload>", "The payload of the wasm message") | ||
.action((options) => { | ||
broadcast(options.address, options.payload); | ||
}); | ||
|
||
program | ||
.command('get-payload') | ||
.requiredOption('--hash, <hash>', 'payload hash') | ||
.action((options) => { | ||
getPayload(options.hash); | ||
}); | ||
|
||
program | ||
.command('subscribe-to-approvals') | ||
.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) | ||
.action((options) => { | ||
subscribe_to_approvals(options.chain, options.startHeight); | ||
}); | ||
|
||
program | ||
.command('subscribe-to-wasm-events') | ||
.option("-s, --start-height <start height>", "The block height to start from (0 = latest)", parseInt, 0) | ||
.action((startHeight) => { | ||
subscribe_to_wasm_events(startHeight) | ||
}); | ||
|
||
program | ||
.command('verify') | ||
.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") | ||
.action((options) => { | ||
verify(options.id, options.sourceChain, options.sourceAddress, options.destinationChain, options.destinationAddress, options.payload); | ||
}); | ||
|
||
program.parse(); |
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, | ||
}; |
Oops, something went wrong.