Mercurial > hg > Database > Christie
diff src/main/java/christie/blockchain/Transaction.java @ 110:eab161e557bd
fix Refactor
author | akahori |
---|---|
date | Mon, 19 Nov 2018 12:31:36 +0900 |
parents | |
children | 0ef25958ac04 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/blockchain/Transaction.java Mon Nov 19 12:31:36 2018 +0900 @@ -0,0 +1,62 @@ +package christie.blockchain; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigInteger; + +// インターフェイスにしたほうがいいかもしれない. 後からdataの内容変える可能性がある. +public class Transaction { + private byte[] hash; + + private long nonce; + + private byte[] sendAddress; + + private byte[] receiveAddress; + + private byte[] data; + + private long timestamp; + + private byte[] signature; + + //public ArrayList<TransactionInput> inputs = new ArrayList<TransactionInput>(); + //public ArrayList<TransactionOutput> outputs = new ArrayList<TransactionOutput>(); + + + public Transaction(byte[] sendAddress, byte[] receiveAddress, byte[] data){ + this.sendAddress = sendAddress; + this.receiveAddress = receiveAddress; + this.data = data; + + } +/* + public Transaction(byte[] from, byte[] to, byte[] value, ArrayList<TransactionInput> inputs) { + this.sendAddress = from; + this.receiveAddress = to; + this.value = value; + this.inputs = inputs; + } +*/ + public byte[] calcHash(){ + HashUtil hashUtil = new HashUtil(); + + byte[] timestampByte = BigInteger.valueOf(this.timestamp).toByteArray(); + + byte[] nonceByte = BigInteger.valueOf(this.nonce).toByteArray(); + + ByteArrayOutputStream output = new ByteArrayOutputStream(); + + try { + output.write(hash); + output.write(timestampByte); + output.write(nonceByte); + } catch (IOException e) { + e.printStackTrace(); + } + + return hashUtil.sha256(output.toByteArray()); + + } + +}