3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 06:44:16 +00:00

Support pubkey only keys in the protobuf serializer.

This commit is contained in:
Mike Hearn 2012-04-07 23:45:40 +02:00
parent cf30280767
commit 71754929e4

View File

@ -99,14 +99,14 @@ public class WalletProtobufSerializer {
} }
for (ECKey key : wallet.getKeys()) { for (ECKey key : wallet.getKeys()) {
walletBuilder.addKey( Protos.Key.Builder buf = Protos.Key.newBuilder()
Protos.Key.newBuilder() .setCreationTimestamp(key.getCreationTimeSeconds() * 1000)
.setCreationTimestamp(key.getCreationTimeSeconds() * 1000) // .setLabel() TODO
// .setLabel() TODO .setType(Protos.Key.Type.ORIGINAL);
.setType(Protos.Key.Type.ORIGINAL) if (key.getPrivKeyBytes() != null)
.setPrivateKey(ByteString.copyFrom(key.getPrivKeyBytes())) buf.setPrivateKey(ByteString.copyFrom(key.getPrivKeyBytes()));
.setPublicKey(ByteString.copyFrom(key.getPubKey())) buf.setPublicKey(ByteString.copyFrom(key.getPubKey()));
); walletBuilder.addKey(buf);
} }
return walletBuilder.build(); return walletBuilder.build();
} }
@ -221,12 +221,12 @@ public class WalletProtobufSerializer {
if (keyProto.getType() != Protos.Key.Type.ORIGINAL) { if (keyProto.getType() != Protos.Key.Type.ORIGINAL) {
throw new IllegalArgumentException("Unknown key type in wallet"); throw new IllegalArgumentException("Unknown key type in wallet");
} }
if (!keyProto.hasPrivateKey()) { byte[] privKey = null;
throw new IllegalArgumentException("Don't know how to handle pubkey-only keys"); if (keyProto.hasPrivateKey()) {
privKey = keyProto.getPrivateKey().toByteArray();
} }
byte[] pubKey = keyProto.hasPublicKey() ? keyProto.getPublicKey().toByteArray() : null; byte[] pubKey = keyProto.hasPublicKey() ? keyProto.getPublicKey().toByteArray() : null;
ECKey ecKey = new ECKey(keyProto.getPrivateKey().toByteArray(), pubKey); ECKey ecKey = new ECKey(privKey, pubKey);
ecKey.setCreationTimeSeconds((keyProto.getCreationTimestamp() + 500) / 1000); ecKey.setCreationTimeSeconds((keyProto.getCreationTimestamp() + 500) / 1000);
wallet.addKey(ecKey); wallet.addKey(ecKey);
} }