• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bernardladenthin / BitcoinAddressFinder / #255

08 Apr 2025 02:52PM UTC coverage: 64.326%. Remained the same
#255

push

bernardladenthin
Changes for org.bitcoinj 0.17, improve NetworkParameters usage.

25 of 26 new or added lines in 11 files covered. (96.15%)

17 existing lines in 2 files now uncovered.

1145 of 1780 relevant lines covered (64.33%)

0.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.72
/src/main/java/net/ladenthin/bitcoinaddressfinder/persistence/PersistenceUtils.java
1
// @formatter:off
2
/**
3
 * Copyright 2020 Bernard Ladenthin bernard.ladenthin@gmail.com
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *    http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
// @formatter:on
19
package net.ladenthin.bitcoinaddressfinder.persistence;
20

21
import java.nio.ByteBuffer;
22
import java.util.ArrayList;
23
import java.util.List;
24
import net.ladenthin.bitcoinaddressfinder.ByteBufferUtility;
25
import org.bitcoinj.base.LegacyAddress;
26
import org.bitcoinj.base.Network;
27
import org.bitcoinj.base.Sha256Hash;
28

29
public class PersistenceUtils {
30

31
    @Deprecated
1✔
32
    private final ByteBuffer emptyByteBuffer = ByteBuffer.allocateDirect(0).asReadOnlyBuffer();
1✔
33
    private final ByteBuffer zeroByteBuffer = longValueToByteBufferDirectAsReadOnlyBuffer(0L);
1✔
34

35
    public final Network network;
36

37
    public PersistenceUtils(Network network) {
1✔
38
        this.network = network;
1✔
39
    }
1✔
40

41
    public ByteBuffer longToByteBufferDirect(long longValue) {
42
        if (longValue == 0) {
1✔
43
            // use the cached zero value to reduce allocations
44
            return zeroByteBuffer;
1✔
45
        }
46
        ByteBuffer newValue = ByteBuffer.allocateDirect(Long.BYTES);
1✔
47
        newValue.putLong(longValue);
1✔
48
        newValue.flip();
1✔
49
        return newValue;
1✔
50
    }
51

52
    @Deprecated
53
    private ByteBuffer addressListToByteBufferDirect(List<LegacyAddress> addresses) {
UNCOV
54
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(LegacyAddress.LENGTH * addresses.size());
×
55
        for (LegacyAddress address : addresses) {
×
56
            byteBuffer.put(address.getHash());
×
57
        }
×
58
        byteBuffer.flip();
×
59
        return byteBuffer;
×
60
    }
61

62
    @Deprecated
63
    private List<LegacyAddress> byteBufferToAddressList(ByteBuffer byteBuffer) {
UNCOV
64
        List<LegacyAddress> addresses = new ArrayList<>();
×
65
        int count = byteBuffer.remaining() / LegacyAddress.LENGTH;
×
66
        for (int i = 0; i < count; i++) {
×
67
            byte[] hash160 = new byte[LegacyAddress.LENGTH];
×
68
            byteBuffer.get(hash160);
×
NEW
69
            addresses.add(LegacyAddress.fromPubKeyHash(network, hash160));
×
70
        }
UNCOV
71
        return addresses;
×
72
    }
73

74
    @Deprecated
75
    private ByteBuffer hashToByteBufferDirect(Sha256Hash hash) {
UNCOV
76
        return new ByteBufferUtility(true).byteArrayToByteBuffer(hash.getBytes());
×
77
    }
78

79
    private ByteBuffer longValueToByteBufferDirectAsReadOnlyBuffer(long value) {
80
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(Long.BYTES);
1✔
81
        byteBuffer.putLong(value);
1✔
82
        return byteBuffer.asReadOnlyBuffer();
1✔
83
    }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc