blockchain icon indicating copy to clipboard operation
blockchain copied to clipboard

Implement createTransaction

Open DanielRrr opened this issue 7 years ago • 7 comments

DanielRrr avatar Feb 07 '18 16:02 DanielRrr

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 avatar Feb 07 '18 18:02 TGOlson

@TGOlson Do I understand correctly that createTransaction should be a kind of generalization of createSimpleTransaction?

DanielRrr avatar Feb 08 '18 15:02 DanielRrr

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 avatar Feb 08 '18 16:02 DanielRrr

@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 avatar Feb 09 '18 00:02 TGOlson

@TGOlson what is type of the return value: something like IO (Either CreateTransactionException Blockchain.Transaction) too?

DanielRrr avatar Feb 09 '18 14:02 DanielRrr

@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 avatar Feb 09 '18 14:02 DanielRrr

@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.

TGOlson avatar Feb 09 '18 20:02 TGOlson