blockchain
blockchain copied to clipboard
Implement createTransaction
Hey Daniel,
The idea behind createTransaction
is that it should accept an arbitrary number of inputs and outputs.
Currently the only transaction builder is createSimpleTransaction
, which accepts just a single private key, and a single output address. This means it is currently only possible to generate a transaction from one address to another address.
createTransaction
should expose the ability to generate transactions from one or more unspent transaction outputs (using multiple private keys), and send those values to one or more target addresses.
@TGOlson Do I understand correctly that createTransaction
should be a kind of generalization of createSimpleTransaction
?
I've found the following TODO in comments:
createTransaction :: [Crypto.KeyPair] -> [(Crypto.PublicKey, Int)] -> Int -> Blockchain.Blockchain Blockchain.Validated -> Either CreateTransactionException Blockchain.Transaction createTransaction _srcs _targets _fee _blockchain = undefined
What Integers should do in this function?
By the way, why don't we use createSimpleTransaction
in createTransaction
?
@DanielRrr correct, I think it should be a generalization of the "simple" case where there is only one input and one output.
That type signature in the comment might be outdated, but generally the new function should be able to accept a list of key pairs ([Crypto.KeyPair]
), and a list of output addresses w/ the specified value to send to those addresses ([(Crypto.PublicKey, Word)]
), and then be able to generate a transaction that fits those specifications (or return an error if necessary).
@TGOlson what is type of the return value: something like IO (Either CreateTransactionException Blockchain.Transaction)
too?
@TGOlson
I suppose that the signature should look approximately as follows
createTransaction :: [Crypto.KeyPair] -> [(Crypto.PublicKey, Word.Word)] -> [Word.Word] -> Blockchain.Blockchain Blockchain.Validated -> IO (Either CreateTransactionException Blockchain.Transaction) -- ^ the return value
or there should be [Blockchain.Transaction]
inside IO?
@DanielRrr I think that signature looks right. If you look at the type for Transaction
, you'll see that each transaction contains a list of inputs and outputs. So I think createTransaction
should only return a single transaction.