Skip to content
Snippets Groups Projects

Markup

Merged Otto Zaiser requested to merge markup into develop
13 files
+ 3082
65
Compare changes
  • Side-by-side
  • Inline
Files
13
+ 38
10
 
import { sign } from "crypto";
 
//const stamperInterface = require('../../contract/build/contracts/Stamper.json')
//const stamperInterface = require('../../contract/build/contracts/Stamper.json')
class Stamper {
class Stamper {
constructor(web3, contractAbi, contractAddress) {
constructor(web3, contractAbi, contractAddress) {
this.web3 = web3
this.web3 = web3
 
this.contractAddress = contractAddress
this.contract = new web3.eth.Contract(contractAbi, contractAddress)
this.contract = new web3.eth.Contract(contractAbi, contractAddress)
}
}
setSender(fromAddress) {
// stampea un conjunto de hashes.
this.from = fromAddress
// si walletAccount es undefined trata de usar la account de web3.eth.defaultAccount
}
async stamp(hashes, walletAccount) {
async stamp(hashes) {
console.log(`stamping ${hashes}`)
console.log(`stamping ${hashes}`)
 
let defaultAccount = (walletAccount) ? walletAccount.address : this.web3.eth.defaultAccount
let hashesToStamp = []
let hashesToStamp = []
for (let i=0; i < hashes.length; i++) {
for (let i=0; i < hashes.length; i++) {
let blockNo = await this.contract.methods.getBlockNo(hashes[i], this.from).call()
let blockNo = await this.contract.methods.getBlockNo(hashes[i], defaultAccount).call()
if (blockNo == 0) hashesToStamp.push(hashes[i])
if (blockNo == 0) hashesToStamp.push(hashes[i])
}
}
@@ -25,10 +27,36 @@ class Stamper {
@@ -25,10 +27,36 @@ class Stamper {
resolve()
resolve()
})
})
let txPromise = this.contract.methods.put(hashesToStamp).send({
let txPromise
from: this.from,
let gasLimit = 2000000
gasLimit: 500000
})
if (walletAccount) {
 
let methodPut = this.contract.methods.put(hashesToStamp)
 
let encodedABI = methodPut.encodeABI()
 
 
let tx = {
 
to: this.contractAddress,
 
// v: 47525974938 * 35 + 2,
 
// v: 47525974938,
 
chainId: '200941592',
 
gas: gasLimit,
 
// gasLimit: gasLimit,
 
data: encodedABI
 
}
 
// tx.v = Buffer.from([47525974938])
 
// tx.nonce = this.web3.utils.toHex(await this.web3.eth.getTransactionCount(defaultAccount))
 
 
let signedTx = await walletAccount.signTransaction(tx)
 
// console.log(signedTx)
 
// txPromise = this.web3.eth.sendSignedTransaction(signedTx)
 
// txPromise = this.web3.eth.sendSignedTransaction('0x' + signedTx.serialize().toString('hex'))
 
txPromise = this.web3.eth.sendSignedTransaction(signedTx.rawTransaction)
 
} else {
 
txPromise = this.contract.methods.put(hashesToStamp).send({
 
from: defaultAccount,
 
gasLimit: gasLimit
 
})
 
}
txPromise.then((receipt) => {
txPromise.then((receipt) => {
console.log(`> hashes stampeados en bloque: ${receipt.blockNumber}`)
console.log(`> hashes stampeados en bloque: ${receipt.blockNumber}`)
Loading