fix logic to add more free Token

pull/788/head
Minh Doan 6 years ago committed by Rongjian Lan
parent 7ac35f04fd
commit 44355edebe
  1. 4
      node/contract.go
  2. 7
      node/node.go
  3. 13
      node/node_handler.go

@ -4,6 +4,7 @@ import (
"crypto/ecdsa"
"math/big"
"strings"
"sync/atomic"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
@ -166,7 +167,8 @@ func (node *Node) AddFaucetContractToPendingTransactions() {
// CallFaucetContract invokes the faucet contract to give the walletAddress initial money
func (node *Node) CallFaucetContract(address common.Address) common.Hash {
return node.callGetFreeToken(address)
nonce := atomic.AddUint64(&node.ContractDeployerCurrentNonce, 1)
return node.callGetFreeTokenWithNonce(address, nonce-1)
}
func (node *Node) callGetFreeToken(address common.Address) common.Hash {

@ -143,9 +143,10 @@ type Node struct {
AccountKey *ecdsa.PrivateKey
// For test only
TestBankKeys []*ecdsa.PrivateKey
ContractDeployerKey *ecdsa.PrivateKey
ContractAddresses []common.Address
TestBankKeys []*ecdsa.PrivateKey
ContractDeployerKey *ecdsa.PrivateKey
ContractDeployerCurrentNonce uint64 // The nonce of the deployer contract at current block
ContractAddresses []common.Address
// Shard group Message Receiver
shardGroupReceiver p2p.GroupReceiver

@ -8,11 +8,13 @@ import (
"math"
"os"
"os/exec"
"sync/atomic"
"time"
"github.com/harmony-one/harmony/core"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
pb "github.com/golang/protobuf/proto"
"github.com/harmony-one/bls/ffi/go/bls"
@ -311,6 +313,17 @@ func (node *Node) PostConsensusProcessing(newBlock *types.Block) {
node.AddNewBlock(newBlock)
if node.Consensus.ShardID == 0 {
// Update contract deployer's nonce so default contract like faucet can issue transaction with current nonce
nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(node.ContractDeployerKey.PublicKey))
atomic.StoreUint64(&node.ContractDeployerCurrentNonce, nonce)
// TODO: enable drand only for beacon chain
// ConfirmedBlockChannel which is listened by drand leader who will initiate DRG if its a epoch block (first block of a epoch)
if node.DRand != nil {
go func() {
node.ConfirmedBlockChannel <- newBlock
}()
}
// ConfirmedBlockChannel which is listened by drand leader who will initiate DRG if its a epoch block (first block of a epoch)
if node.DRand != nil {

Loading…
Cancel
Save