Skip to content
Snippets Groups Projects
Unverified Commit b8e88c5b authored by Luca Moser's avatar Luca Moser Committed by GitHub
Browse files

sign the faucet tx (#586)

parent 94a77f55
No related branches found
No related tags found
No related merge requests found
...@@ -91,12 +91,12 @@ func configure(*node.Plugin) { ...@@ -91,12 +91,12 @@ func configure(*node.Plugin) {
fundingWorkerPool = workerpool.New(func(task workerpool.Task) { fundingWorkerPool = workerpool.New(func(task workerpool.Task) {
msg := task.Param(0).(*message.Message) msg := task.Param(0).(*message.Message)
addr := msg.Payload().(*faucetpayload.Payload).Address() addr := msg.Payload().(*faucetpayload.Payload).Address()
_, txID, err := Faucet().SendFunds(msg) msg, txID, err := Faucet().SendFunds(msg)
if err != nil { if err != nil {
log.Errorf("couldn't fulfill funding request to %s: %s", addr, err) log.Errorf("couldn't fulfill funding request to %s: %s", addr, err)
return return
} }
log.Infof("sent funds to address %s via tx %s", addr, txID) log.Infof("sent funds to address %s via tx %s and msg %s", addr, txID, msg.Id().String())
}, workerpool.WorkerCount(fundingWorkerCount), workerpool.QueueSize(fundingWorkerQueueSize)) }, workerpool.WorkerCount(fundingWorkerCount), workerpool.QueueSize(fundingWorkerQueueSize))
configureEvents() configureEvents()
......
...@@ -7,16 +7,16 @@ import ( ...@@ -7,16 +7,16 @@ import (
"time" "time"
faucetpayload "github.com/iotaledger/goshimmer/dapps/faucet/packages/payload" faucetpayload "github.com/iotaledger/goshimmer/dapps/faucet/packages/payload"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/goshimmer/dapps/valuetransfers" "github.com/iotaledger/goshimmer/dapps/valuetransfers"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address/signaturescheme"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/tangle" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/tangle"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/wallet" "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/wallet"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
"github.com/iotaledger/goshimmer/plugins/issuer" "github.com/iotaledger/goshimmer/plugins/issuer"
"github.com/iotaledger/hive.go/events"
) )
var ( var (
...@@ -55,7 +55,7 @@ func (f *Faucet) SendFunds(msg *message.Message) (m *message.Message, txID strin ...@@ -55,7 +55,7 @@ func (f *Faucet) SendFunds(msg *message.Message) (m *message.Message, txID strin
addr := msg.Payload().(*faucetpayload.Payload).Address() addr := msg.Payload().(*faucetpayload.Payload).Address()
// get the output ids for the inputs and remainder balance // get the output ids for the inputs and remainder balance
outputIds, remainder := f.collectUTXOsForFunding() outputIds, addrsIndices, remainder := f.collectUTXOsForFunding()
tx := transaction.New( tx := transaction.New(
// inputs // inputs
...@@ -75,6 +75,10 @@ func (f *Faucet) SendFunds(msg *message.Message) (m *message.Message, txID strin ...@@ -75,6 +75,10 @@ func (f *Faucet) SendFunds(msg *message.Message) (m *message.Message, txID strin
tx.Outputs().Add(remainAddr, []*balance.Balance{balance.New(balance.ColorIOTA, remainder)}) tx.Outputs().Add(remainAddr, []*balance.Balance{balance.New(balance.ColorIOTA, remainder)})
} }
for index := range addrsIndices {
tx.Sign(signaturescheme.ED25519(*f.wallet.Seed().KeyPair(index)))
}
// prepare value payload with value factory // prepare value payload with value factory
payload := valuetransfers.ValueObjectFactory().IssueTransaction(tx) payload := valuetransfers.ValueObjectFactory().IssueTransaction(tx)
...@@ -125,9 +129,10 @@ func (f *Faucet) awaitTransactionBooked(txID transaction.ID, maxAwait time.Durat ...@@ -125,9 +129,10 @@ func (f *Faucet) awaitTransactionBooked(txID transaction.ID, maxAwait time.Durat
// collectUTXOsForFunding iterates over the faucet's UTXOs until the token threshold is reached. // collectUTXOsForFunding iterates over the faucet's UTXOs until the token threshold is reached.
// this function also returns the remainder balance for the given outputs. // this function also returns the remainder balance for the given outputs.
func (f *Faucet) collectUTXOsForFunding() (outputIds []transaction.OutputID, remainder int64) { func (f *Faucet) collectUTXOsForFunding() (outputIds []transaction.OutputID, addrsIndices map[uint64]struct{}, remainder int64) {
var total = f.tokensPerRequest var total = f.tokensPerRequest
var i uint64 var i uint64
addrsIndices = map[uint64]struct{}{}
// get a list of address for inputs // get a list of address for inputs
for i = 0; total > 0; i++ { for i = 0; total > 0; i++ {
...@@ -141,6 +146,7 @@ func (f *Faucet) collectUTXOsForFunding() (outputIds []transaction.OutputID, rem ...@@ -141,6 +146,7 @@ func (f *Faucet) collectUTXOsForFunding() (outputIds []transaction.OutputID, rem
for _, coloredBalance := range output.Balances() { for _, coloredBalance := range output.Balances() {
val += coloredBalance.Value val += coloredBalance.Value
} }
addrsIndices[i] = struct{}{}
// get unspent output ids and check if it's conflict // get unspent output ids and check if it's conflict
if val <= total { if val <= total {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment