Skip to content
Snippets Groups Projects
Commit b3b4ae4f authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Timestamps en el log. Y ahora internamente nos preocupamos por el nonce.

parent ddefb29e
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ class Stamper { ...@@ -11,7 +11,7 @@ class Stamper {
// utiliza la cuenta walletAccount para enviar la transaccion // utiliza la cuenta walletAccount para enviar la transaccion
// (o defaultAccount si no se especifica) // (o defaultAccount si no se especifica)
async stamp(objects, walletAccount) { async stamp(objects, walletAccount) {
console.log(`stamping ${objects}`) console.log(`asked to stamp ${objects}`)
// si walletAccount es undefined trata de usar la account de web3.eth.defaultAccount // si walletAccount es undefined trata de usar la account de web3.eth.defaultAccount
let defaultAccount = (walletAccount) ? walletAccount.address : this.web3.eth.defaultAccount let defaultAccount = (walletAccount) ? walletAccount.address : this.web3.eth.defaultAccount
...@@ -19,13 +19,21 @@ class Stamper { ...@@ -19,13 +19,21 @@ class Stamper {
for (let i=0; i < objects.length; i++) { for (let i=0; i < objects.length; i++) {
let blockNo = await this.contract.methods.getBlockNo(objects[i], defaultAccount).call() let blockNo = await this.contract.methods.getBlockNo(objects[i], defaultAccount).call()
if (blockNo == 0) objectsToStamp.push(objects[i]) if (blockNo == 0)
{
objectsToStamp.push(objects[i])
}
else
{
console.log(`already stamped: ` + objects[i] );
}
} }
if (objectsToStamp.length == 0) return new Promise( (resolve) => { if (objectsToStamp.length == 0) return new Promise( (resolve) => {
console.log(`Los objects enviados ya están stampeados`) console.log(`Los objects enviados ya están stampeados`)
resolve() resolve()
}) })
console.log(`stamping ` + objectsToStamp.join(', ') );
let txPromise let txPromise
let gasLimit = 2000000 let gasLimit = 2000000
...@@ -42,7 +50,8 @@ class Stamper { ...@@ -42,7 +50,8 @@ class Stamper {
//chainId: '200941592', //chainId: '200941592',
gas: gasLimit, gas: gasLimit,
// gasLimit: gasLimit, // gasLimit: gasLimit,
data: encodedABI data: encodedABI,
nonce: this.web3.bfa.txnonce++
} }
// tx.v = Buffer.from([47525974938]) // tx.v = Buffer.from([47525974938])
// tx.nonce = this.web3.utils.toHex(await this.web3.eth.getTransactionCount(defaultAccount)) // tx.nonce = this.web3.utils.toHex(await this.web3.eth.getTransactionCount(defaultAccount))
......
...@@ -43,6 +43,9 @@ async function setupWeb3() { ...@@ -43,6 +43,9 @@ async function setupWeb3() {
// se trata de utilizar una que haya abierta // se trata de utilizar una que haya abierta
web3.eth.defaultAccount = (await web3.eth.getAccounts())[0] web3.eth.defaultAccount = (await web3.eth.getAccounts())[0]
} }
web3.bfa = {
txnonce: await web3.eth.getTransactionCount(web3.eth.defaultAccount),
}
/***************************************************/ /***************************************************/
// Carga de contrato // Carga de contrato
...@@ -102,6 +105,7 @@ if ( process.env.API_USER && process.env.API_PASS ) { ...@@ -102,6 +105,7 @@ if ( process.env.API_USER && process.env.API_PASS ) {
// API Endpoints // API Endpoints
/***************************************************/ /***************************************************/
app.get('/wait1block', async (req, res) => { app.get('/wait1block', async (req, res) => {
console.log( Date() + ": /wait1block" );
let ss = new Stamper(web3, contractAbi, contractAddress) let ss = new Stamper(web3, contractAbi, contractAddress)
try { try {
...@@ -119,6 +123,7 @@ app.get('/wait1block', async (req, res) => { ...@@ -119,6 +123,7 @@ app.get('/wait1block', async (req, res) => {
} }
}) })
app.post('/stamp', async (req, res) => { app.post('/stamp', async (req, res) => {
console.log( Date() + ": /stamp " + req.body.hashes.join(', ') );
let ss = new Stamper(web3, contractAbi, contractAddress) let ss = new Stamper(web3, contractAbi, contractAddress)
if ( ! ("hashes" in req.body) ) if ( ! ("hashes" in req.body) )
...@@ -158,6 +163,7 @@ app.post('/stamp', async (req, res) => { ...@@ -158,6 +163,7 @@ app.post('/stamp', async (req, res) => {
}) })
app.get('/verify/:hash', async (req, res) => { app.get('/verify/:hash', async (req, res) => {
console.log( Date() + ": /verify/:" + req.params.hash );
let ss = new Stamper(web3, contractAbi, contractAddress) let ss = new Stamper(web3, contractAbi, contractAddress)
var value = req.params.hash var value = req.params.hash
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment