From 557632aef474d7ff310a83e292f117b0502dbdba Mon Sep 17 00:00:00 2001 From: duanyytop Date: Tue, 10 Dec 2019 16:33:29 +0800 Subject: [PATCH 1/3] chore: remove useless code --- .../nervos/ckb/transaction/CellCollector.java | 143 +----------------- 1 file changed, 4 insertions(+), 139 deletions(-) diff --git a/example/src/main/java/org/nervos/ckb/transaction/CellCollector.java b/example/src/main/java/org/nervos/ckb/transaction/CellCollector.java index 42037f6ef..f53494cf0 100644 --- a/example/src/main/java/org/nervos/ckb/transaction/CellCollector.java +++ b/example/src/main/java/org/nervos/ckb/transaction/CellCollector.java @@ -4,10 +4,11 @@ import java.math.BigInteger; import java.util.*; import org.nervos.ckb.service.Api; -import org.nervos.ckb.system.SystemContract; -import org.nervos.ckb.system.type.SystemScriptCell; import org.nervos.ckb.type.Witness; -import org.nervos.ckb.type.cell.*; +import org.nervos.ckb.type.cell.CellInput; +import org.nervos.ckb.type.cell.CellOutput; +import org.nervos.ckb.type.cell.CellOutputWithOutPoint; +import org.nervos.ckb.type.cell.CellWithStatus; import org.nervos.ckb.type.transaction.Transaction; import org.nervos.ckb.utils.Calculator; import org.nervos.ckb.utils.Numeric; @@ -32,142 +33,6 @@ public CellCollector(Api api) { this.skipDataAndType = true; } - public CollectResult collectInputs( - List addresses, - List cellOutputs, - BigInteger feeRate, - int initialLength, - List cellDeps, - List outputsData, - List headerDeps) - throws IOException { - - List lockHashes = new ArrayList<>(); - for (String address : addresses) { - AddressParseResult addressParseResult = AddressParser.parse(address); - lockHashes.add(addressParseResult.script.computeHash()); - } - List cellOutputsData = new ArrayList<>(); - for (int i = 0; i < cellOutputs.size() - 1; i++) { - BigInteger size = cellOutputs.get(i).occupiedCapacity("0x"); - if (size.compareTo(Numeric.toBigInt(cellOutputs.get(i).capacity)) > 0) { - throw new IOException("Cell output byte size must not be bigger than capacity"); - } - cellOutputsData.add("0x"); - } - SystemScriptCell systemScriptCell = SystemContract.getSystemSecpCell(api); - cellOutputsData.add("0x"); - - if (outputsData != null && outputsData.size() > 0) { - cellOutputsData = outputsData; - } - - List cellDepList = - Collections.singletonList(new CellDep(systemScriptCell.outPoint, CellDep.DEP_GROUP)); - if (cellDeps != null && cellDeps.size() > 0) { - cellDepList = cellDeps; - } - - List headerDepList = Collections.emptyList(); - if (headerDeps != null && headerDeps.size() > 0) { - headerDepList = headerDeps; - } - - Transaction transaction = - new Transaction( - "0", - cellDepList, - headerDepList, - Collections.emptyList(), - cellOutputs, - cellOutputsData, - Collections.emptyList()); - - BigInteger inputsCapacity = BigInteger.ZERO; - List cellInputs = new ArrayList<>(); - Map> lockInputsMap = new HashMap<>(); - for (String lockHash : lockHashes) { - lockInputsMap.put(lockHash, new ArrayList<>()); - } - List witnesses = new ArrayList<>(); - - CellOutput changeOutput = cellOutputs.get(cellOutputs.size() - 1); - - BigInteger needCapacity = BigInteger.ZERO; - for (CellOutput cellOutput : cellOutputs) { - needCapacity = needCapacity.add(Numeric.toBigInt(cellOutput.capacity)); - } - List cellOutputList; - for (int index = 0; index < lockHashes.size(); index++) { - long toBlockNumber = api.getTipBlockNumber().longValue(); - long fromBlockNumber = 1; - - while (fromBlockNumber <= toBlockNumber - && inputsCapacity.compareTo(needCapacity.add(calculateTxFee(transaction, feeRate))) < 0) { - long currentToBlockNumber = Math.min(fromBlockNumber + 100, toBlockNumber); - cellOutputList = - api.getCellsByLockHash( - lockHashes.get(index), - BigInteger.valueOf(fromBlockNumber).toString(), - BigInteger.valueOf(currentToBlockNumber).toString()); - for (CellOutputWithOutPoint cellOutputWithOutPoint : cellOutputList) { - if (skipDataAndType) { - CellWithStatus cellWithStatus = api.getLiveCell(cellOutputWithOutPoint.outPoint, true); - String outputsDataContent = cellWithStatus.cell.data.content; - CellOutput cellOutput = cellWithStatus.cell.output; - if ((!Strings.isEmpty(outputsDataContent) && !"0x".equals(outputsDataContent)) - || cellOutput.type != null) { - continue; - } - } - CellInput cellInput = new CellInput(cellOutputWithOutPoint.outPoint, "0x0"); - inputsCapacity = inputsCapacity.add(Numeric.toBigInt(cellOutputWithOutPoint.capacity)); - List cellInputList = lockInputsMap.get(lockHashes.get(index)); - cellInputList.add(cellInput); - cellInputs.add(cellInput); - witnesses.add("0x"); - transaction.inputs = cellInputs; - transaction.witnesses = witnesses; - BigInteger sumNeedCapacity = - needCapacity - .add(calculateTxFee(transaction, feeRate)) - .add(calculateOutputSize(changeOutput)); - if (inputsCapacity.compareTo(sumNeedCapacity) > 0) { - // update witness of group first element - int witnessIndex = 0; - for (String lockHash : lockHashes) { - if (lockInputsMap.get(lockHash).size() == 0) break; - witnesses.set(witnessIndex, new Witness(NumberUtils.getZeros(initialLength))); - witnessIndex += lockInputsMap.get(lockHash).size(); - } - transaction.witnesses = witnesses; - // calculate sum need capacity again - sumNeedCapacity = - needCapacity - .add(calculateTxFee(transaction, feeRate)) - .add(calculateOutputSize(changeOutput)); - if (inputsCapacity.compareTo(sumNeedCapacity) > 0) { - break; - } - } - } - fromBlockNumber = currentToBlockNumber + 1; - } - } - if (inputsCapacity.compareTo(needCapacity.add(calculateTxFee(transaction, feeRate))) < 0) { - throw new IOException("Capacity not enough!"); - } - BigInteger changeCapacity = - inputsCapacity.subtract(needCapacity.add(calculateTxFee(transaction, feeRate))); - List cellsWithAddresses = new ArrayList<>(); - for (Map.Entry> entry : lockInputsMap.entrySet()) { - cellsWithAddresses.add( - new CellsWithAddress( - entry.getValue(), addresses.get(lockHashes.indexOf(entry.getKey())))); - } - return new CollectResult(cellsWithAddresses, Numeric.toHexStringWithPrefix(changeCapacity)); - } - public CollectResult collectInputs( List addresses, Transaction tx, BigInteger feeRate, int initialLength) throws IOException { From 4dc91a9cbf9481a1bc9d5b1282e6ecdd80053b0e Mon Sep 17 00:00:00 2001 From: duanyytop Date: Fri, 13 Dec 2019 21:28:58 +0800 Subject: [PATCH 2/3] docs: update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37e8b2a26..9f2ed5cbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [v0.26.0](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.26.0-rc2...v0.26.0) (2019-12-14) + +### Refactor + +* Remove useless code ([557632a](https://github.com/nervosnetwork/ckb-sdk-java/commit/557632aef474d7ff310a83e292f117b0502dbdba)) + # [v0.26.0-rc2](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.25.0...v0.26.0-rc2) (2019-12-8) ### Feature From 7a5b2cb3c44833f3fd5d9d819b9b69ce5ff50fa9 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Fri, 13 Dec 2019 21:30:16 +0800 Subject: [PATCH 3/3] chore: bump version to v0.26.0 --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index f6513010c..037a82f01 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ allprojects { targetCompatibility = 1.8 group 'org.nervos.ckb' - version '0.26.0-rc2' + version '0.26.0' apply plugin: 'java' @@ -113,7 +113,7 @@ configure(subprojects.findAll { it.name != 'tests' }) { publications { mavenJava(MavenPublication) { groupId 'org.nervos.ckb' - version '0.26.0-rc2' + version '0.26.0' from components.java } }