In my application i must follow the use case:
I need to record any document hash on the Ropsten (eth testnet) blockchain. The hash is unique and i'm using a mapping in my smart contract to accomplish this. Got no problem with that.
Since the hash is unique, if the user tries to put an already document hash registered on the blockchain, he will get a treated catch error by me. At this moment, below the treated message, I want to show the hash of the transaction that has the document hash already registered.
If it is possible, maybe i will have to encode the document hash to match with the encode input data of transaction.
I know how to get a transaction data by his hash transaction (getTransaction(txHash, callback))
.
The question is: Is there another way to get a transaction datas other than by his own hash (txHash)?
Currently i'm using web3js 1.0.0 for eth client.
Sorry for my bad english :|
EDIT:
Here is what i'm thinking to do.
In my case, if the document hash already was registered in the input data field of transaction, i want to show the transaction hash.
So to begin, a little test is get a transaction list of a block. I'm passing each tx hash to (getTransaction(txHash, callback)), but i'm facing a problem that i can't get the callback of getTransaction.
My code:
async function getInputTransaction(tx) {
web3.eth.getTransaction(tx, function(err, cb){
console.log('got here');
let decodeInput = web3.utils.hexToAscii(cb.input);
decodeInput = decodeInput.split("_").pop();
if(!err){
console.log(cb);
console.error('\nInput decoded: ' + '\u001b[1;32m' + decodeInput + '\u001b[0m');
}else{
console.error('error: ' + error);
}}
)
}
var tx;
web3.eth.getBlock(6339515, function(err, result){
for(var i = 0; i <= result.transactions.length; i++){
tx = result.transactions[i];
getInputTransaction(tx).
then(function() {
})
.catch(function(error) {
console.log('error: \n' + error);
});
}
})
When i debug, the callback "cb" is not been triggered.