Mercurial > hg > Database > Christie
view src/main/java/christie/blockchain/Transaction.java @ 121:8949d0ecf1f6
refactor Topology
author | akahori |
---|---|
date | Tue, 11 Dec 2018 15:46:09 +0900 |
parents | eab161e557bd |
children | 0ef25958ac04 |
line wrap: on
line source
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()); } }