-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tx-status to handle account id better
- Loading branch information
Showing
4 changed files
with
46 additions
and
31 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,37 @@ | ||
const exitOnError = require('../utils/exit-on-error'); | ||
const connect = require('../utils/connect'); | ||
const inspectResponse = require('../utils/inspect-response'); | ||
const bs58 = require('bs58'); | ||
|
||
module.exports = { | ||
command: 'tx-status <hash>', | ||
desc: 'lookup transaction status by hash', | ||
builder: (yargs) => yargs | ||
.option('hash', { | ||
desc: 'base58-encoded hash', | ||
type: 'string', | ||
required: true | ||
}), | ||
handler: exitOnError(async (argv) => { | ||
const near = await connect(argv) | ||
|
||
const hashParts = argv.hash.split(':'); | ||
let hash, accountId; | ||
if (hashParts.length == 2) { | ||
[accountId, hash] = hashParts; | ||
} else if (hashParts.length == 1) { | ||
[hash] = hashParts; | ||
} else { | ||
throw new Error('Unexpected transaction hash format'); | ||
} | ||
accountId = accountId || argv.accountId || argv.masterAccount | ||
|
||
if (!accountId) { | ||
throw new Error('Please specify account id, either as part of transaction hash or using --accountId flag.') | ||
} | ||
|
||
const status = await near.connection.provider.txStatus(bs58.decode(hash), accountId); | ||
console.log(`Transaction ${accountId}:${hash}`); | ||
console.log(inspectResponse(status)); | ||
}) | ||
}; |
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,5 @@ | ||
|
||
const util = require('util'); | ||
module.exports = (response) => { | ||
return util.inspect(response, { showHidden: false, depth: null, colors: true }); | ||
}; |