/** * Calculates a PMT given the list of leaf hashes and which leaves need to be included. The relevant interior hashes * are calculated and a new PMT returned. */ public static PartialMerkleTree buildFromLeaves(NetworkParameters params, byte[] includeBits, List<Sha256Hash> allLeafHashes) { // Calculate height of the tree. int height = 0; while (getTreeWidth(allLeafHashes.size(), height) > 1) height++; List<Boolean> bitList = new ArrayList<>(); List<Sha256Hash> hashes = new ArrayList<>(); traverseAndBuild(height, 0, allLeafHashes, includeBits, bitList, hashes); byte[] bits = new byte[(int)Math.ceil(bitList.size() / 8.0)]; for (int i = 0; i < bitList.size(); i++) if (bitList.get(i)) Utils.setBitLE(bits, i); return new PartialMerkleTree(params, bits, hashes, allLeafHashes.size()); }
/** * Calculates a PMT given the list of leaf hashes and which leaves need to be included. The relevant interior hashes * are calculated and a new PMT returned. */ public static PartialMerkleTree buildFromLeaves(NetworkParameters params, byte[] includeBits, List<Sha256Hash> allLeafHashes) { // Calculate height of the tree. int height = 0; while (getTreeWidth(allLeafHashes.size(), height) > 1) height++; List<Boolean> bitList = new ArrayList<>(); List<Sha256Hash> hashes = new ArrayList<>(); traverseAndBuild(height, 0, allLeafHashes, includeBits, bitList, hashes); byte[] bits = new byte[(int)Math.ceil(bitList.size() / 8.0)]; for (int i = 0; i < bitList.size(); i++) if (bitList.get(i)) Utils.setBitLE(bits, i); return new PartialMerkleTree(params, bits, hashes, allLeafHashes.size()); }
/** * Calculates a PMT given the list of leaf hashes and which leaves need to be included. The relevant interior hashes * are calculated and a new PMT returned. */ public static PartialMerkleTree buildFromLeaves(NetworkParameters params, byte[] includeBits, List<Sha256Hash> allLeafHashes) { // Calculate height of the tree. int height = 0; while (getTreeWidth(allLeafHashes.size(), height) > 1) height++; List<Boolean> bitList = new ArrayList<Boolean>(); List<Sha256Hash> hashes = new ArrayList<Sha256Hash>(); traverseAndBuild(height, 0, allLeafHashes, includeBits, bitList, hashes); byte[] bits = new byte[(int)Math.ceil(bitList.size() / 8.0)]; for (int i = 0; i < bitList.size(); i++) if (bitList.get(i)) Utils.setBitLE(bits, i); return new PartialMerkleTree(params, bits, hashes, allLeafHashes.size()); }
/** * Calculates a PMT given the list of leaf hashes and which leaves need to be included. The relevant interior hashes * are calculated and a new PMT returned. */ public static PartialMerkleTree buildFromLeaves(NetworkParameters params, byte[] includeBits, List<Sha256Hash> allLeafHashes) { // Calculate height of the tree. int height = 0; while (getTreeWidth(allLeafHashes.size(), height) > 1) height++; List<Boolean> bitList = new ArrayList<Boolean>(); List<Sha256Hash> hashes = new ArrayList<Sha256Hash>(); traverseAndBuild(height, 0, allLeafHashes, includeBits, bitList, hashes); byte[] bits = new byte[(int)Math.ceil(bitList.size() / 8.0)]; for (int i = 0; i < bitList.size(); i++) if (bitList.get(i)) Utils.setBitLE(bits, i); return new PartialMerkleTree(params, bits, hashes, allLeafHashes.size()); }
@Override protected void parse() throws ProtocolException { byte[] headerBytes = new byte[Block.HEADER_SIZE]; System.arraycopy(payload, 0, headerBytes, 0, Block.HEADER_SIZE); header = params.getDefaultSerializer().makeBlock(headerBytes); merkleTree = new PartialMerkleTree(params, payload, Block.HEADER_SIZE); length = Block.HEADER_SIZE + merkleTree.getMessageSize(); }
@Override protected void parse() throws ProtocolException { byte[] headerBytes = new byte[Block.HEADER_SIZE]; System.arraycopy(payload, 0, headerBytes, 0, Block.HEADER_SIZE); header = params.getDefaultSerializer().makeBlock(headerBytes); merkleTree = new PartialMerkleTree(params, payload, Block.HEADER_SIZE); length = Block.HEADER_SIZE + merkleTree.getMessageSize(); }
@Override protected void parse() throws ProtocolException { byte[] headerBytes = new byte[Block.HEADER_SIZE]; System.arraycopy(payload, 0, headerBytes, 0, Block.HEADER_SIZE); header = params.getDefaultSerializer().makeBlock(headerBytes); merkleTree = new PartialMerkleTree(params, payload, Block.HEADER_SIZE); length = Block.HEADER_SIZE + merkleTree.getMessageSize(); }
@Override protected void parse() throws ProtocolException { byte[] headerBytes = new byte[Block.HEADER_SIZE]; System.arraycopy(payload, 0, headerBytes, 0, Block.HEADER_SIZE); header = params.getDefaultSerializer().makeBlock(headerBytes); merkleTree = new PartialMerkleTree(params, payload, Block.HEADER_SIZE); length = Block.HEADER_SIZE + merkleTree.getMessageSize(); }
@Override public FilteredBlock makeFilteredBlock(byte[] payloadBytes) throws ProtocolException { long blockVersion = Utils.readUint32(payloadBytes, 0); int headerSize = Block.HEADER_SIZE; byte[] headerBytes = new byte[Block.HEADER_SIZE + 1]; System.arraycopy(payloadBytes, 0, headerBytes, 0, headerSize); headerBytes[80] = 0; // Need to provide 0 transactions so the block header can be constructed if (this.getParameters() instanceof AuxPoWNetworkParameters) { final AuxPoWNetworkParameters auxPoWParams = (AuxPoWNetworkParameters) this.getParameters(); if (auxPoWParams.isAuxPoWBlockVersion(blockVersion)) { final AltcoinBlock header = (AltcoinBlock) makeBlock(headerBytes, 0, Message.UNKNOWN_LENGTH); final AuxPoW auxpow = new AuxPoW(this.getParameters(), payloadBytes, Block.HEADER_SIZE, null, this); header.setAuxPoW(auxpow); int pmtOffset = headerSize + auxpow.getMessageSize(); int pmtLength = payloadBytes.length - pmtOffset; byte[] pmtBytes = new byte[pmtLength]; System.arraycopy(payloadBytes, pmtOffset, pmtBytes, 0, pmtLength); PartialMerkleTree pmt = new PartialMerkleTree(this.getParameters(), pmtBytes, 0); return new FilteredBlock(this.getParameters(), header, pmt); } } // We are either not in AuxPoW mode, or the block is not an AuxPoW block. return super.makeFilteredBlock(payloadBytes); } }