mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 07:12:17 +00:00
Serialize key creation time.
Resolves issue 151.
This commit is contained in:
parent
0d195e17c8
commit
789798bae0
@ -100,7 +100,7 @@ public class WalletProtobufSerializer {
|
||||
for (ECKey key : wallet.getKeys()) {
|
||||
walletBuilder.addKey(
|
||||
Protos.Key.newBuilder()
|
||||
// .setCreationTimestamp() TODO
|
||||
.setCreationTimestamp(key.getCreationTimeSeconds() * 1000)
|
||||
// .setLabel() TODO
|
||||
.setType(Protos.Key.Type.ORIGINAL)
|
||||
.setPrivateKey(ByteString.copyFrom(key.getPrivKeyBytes()))
|
||||
@ -231,7 +231,9 @@ public class WalletProtobufSerializer {
|
||||
}
|
||||
|
||||
byte[] pubKey = keyProto.hasPublicKey() ? keyProto.getPublicKey().toByteArray() : null;
|
||||
wallet.addKey(new ECKey(keyProto.getPrivateKey().toByteArray(), pubKey));
|
||||
ECKey ecKey = new ECKey(keyProto.getPrivateKey().toByteArray(), pubKey);
|
||||
ecKey.setCreationTimeSeconds((keyProto.getCreationTimestamp() + 500) / 1000);
|
||||
wallet.addKey(ecKey);
|
||||
}
|
||||
|
||||
// Read all transactions and create outputs
|
||||
|
@ -32,6 +32,7 @@ public class WalletProtobufSerializerTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
myKey = new ECKey();
|
||||
myKey.setCreationTimeSeconds(123456789L);
|
||||
myAddress = myKey.toAddress(params);
|
||||
wallet = new Wallet(params);
|
||||
wallet.addKey(myKey);
|
||||
@ -49,11 +50,16 @@ public class WalletProtobufSerializerTest {
|
||||
wallet.receiveFromBlock(t1, null, BlockChain.NewBlockType.BEST_CHAIN);
|
||||
|
||||
wallet1 = roundTrip(wallet);
|
||||
assertArrayEquals(myKey.getPubKey(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey());
|
||||
assertArrayEquals(myKey.getPrivKeyBytes(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPrivKeyBytes());
|
||||
assertArrayEquals(myKey.getPubKey(),
|
||||
wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey());
|
||||
assertArrayEquals(myKey.getPrivKeyBytes(),
|
||||
wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPrivKeyBytes());
|
||||
assertEquals(myKey.getCreationTimeSeconds(),
|
||||
wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getCreationTimeSeconds());
|
||||
assertEquals(1, wallet1.getTransactions(true, true).size());
|
||||
assertEquals(v1, wallet1.getBalance());
|
||||
assertArrayEquals(t1.bitcoinSerialize(),wallet1.getTransaction(t1.getHash()).bitcoinSerialize());
|
||||
assertArrayEquals(t1.bitcoinSerialize(),
|
||||
wallet1.getTransaction(t1.getHash()).bitcoinSerialize());
|
||||
|
||||
Protos.Wallet walletProto = WalletProtobufSerializer.walletToProto(wallet);
|
||||
assertEquals(Protos.Key.Type.ORIGINAL, walletProto.getKey(0).getType());
|
||||
|
Loading…
Reference in New Issue
Block a user