2012-01-11 18:04:00 +00:00
|
|
|
/** Copyright 2012 Google Inc.
|
2012-01-06 22:50:34 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2012-01-11 18:04:00 +00:00
|
|
|
* Authors: Jim Burton, Miron Cuperman
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Notes:
|
|
|
|
* - Endianness: All byte arrays that represent numbers (such as hashes and private keys) are Big Endian (a.k.a. network order)
|
2012-01-06 22:50:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package wallet;
|
|
|
|
|
|
|
|
option java_package = "org.bitcoinj.wallet";
|
|
|
|
option java_outer_classname = "Protos";
|
|
|
|
|
2012-01-26 18:43:15 +00:00
|
|
|
/**
|
|
|
|
* A key use to control Bitcoin spending
|
|
|
|
*
|
|
|
|
* Either the private key, the public key or both may be present. It is recommended that
|
|
|
|
* if the private key is provided that the public key is provided too because deriving it is slow.
|
|
|
|
*
|
|
|
|
* If only the public key is provided, the key can only be used to watch the blockchain and verify
|
|
|
|
* transactions, and not for spending.
|
|
|
|
*/
|
2012-01-10 19:10:15 +00:00
|
|
|
message Key {
|
2012-01-11 18:04:00 +00:00
|
|
|
enum Type {
|
|
|
|
ORIGINAL = 1; // Original bitcoin secp256k1 curve
|
|
|
|
}
|
2012-01-26 18:43:15 +00:00
|
|
|
required Type type = 1;
|
2012-04-15 17:07:02 +00:00
|
|
|
|
|
|
|
// The private EC key bytes without any ASN.1 wrapping.
|
|
|
|
optional bytes private_key = 2;
|
|
|
|
// The public EC key derived from the private key. We allow both to be stored to avoid mobile clients having to
|
|
|
|
// do lots of slow EC math on startup.
|
|
|
|
optional bytes public_key = 3;
|
|
|
|
|
|
|
|
// User-provided label associated with the key.
|
|
|
|
optional string label = 4;
|
|
|
|
|
|
|
|
// Timestamp stored as millis since epoch. Useful for skipping block bodies before this point.
|
|
|
|
optional int64 creation_timestamp = 5;
|
2012-01-10 19:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message TransactionInput {
|
2012-04-15 17:07:02 +00:00
|
|
|
// Hash of the transaction this input is using.
|
2012-01-10 19:10:15 +00:00
|
|
|
required bytes transaction_out_point_hash = 1;
|
2012-04-15 17:07:02 +00:00
|
|
|
// Index of transaction output used by this input.
|
2012-01-10 19:10:15 +00:00
|
|
|
required int32 transaction_out_point_index = 2;
|
2012-04-15 17:07:02 +00:00
|
|
|
// Script that contains the signatures/pubkeys.
|
|
|
|
required bytes script_bytes = 3;
|
|
|
|
// Sequence number. Currently unused, but intended for contracts in future.
|
|
|
|
optional uint32 sequence = 4;
|
2012-01-10 19:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
message TransactionOutput {
|
|
|
|
required int64 value = 1;
|
|
|
|
required bytes script_bytes = 2; // script of transaction output
|
2012-04-15 17:07:02 +00:00
|
|
|
// If spent, the hash of the transaction doing the spend.
|
|
|
|
optional bytes spent_by_transaction_hash = 3;
|
|
|
|
// If spent, the index of the transaction input of the transaction doing the spend.
|
2012-01-10 19:10:15 +00:00
|
|
|
optional int32 spent_by_transaction_index = 4;
|
|
|
|
}
|
|
|
|
|
2012-01-26 18:43:15 +00:00
|
|
|
/**
|
|
|
|
* A description of the confidence we have that a transaction cannot be reversed in the future.
|
|
|
|
*
|
|
|
|
* Parsing should be lenient, since this could change for different applications yet we should
|
|
|
|
* maintain backward compatibility.
|
|
|
|
*/
|
|
|
|
|
2012-01-25 18:40:20 +00:00
|
|
|
message TransactionConfidence {
|
|
|
|
enum Type {
|
|
|
|
UNKNOWN = 0;
|
2012-01-26 18:43:15 +00:00
|
|
|
BUILDING = 1; // In best chain. If and only if appeared_at_height is present.
|
|
|
|
NOT_SEEN_IN_CHAIN = 2; // Pending inclusion in best chain.
|
|
|
|
NOT_IN_BEST_CHAIN = 3; // In non-best chain, pending inclusion in best chain.
|
|
|
|
OVERRIDDEN_BY_DOUBLE_SPEND = 4; // If and only if overriding_transaction is present.
|
2012-01-25 18:40:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 18:43:15 +00:00
|
|
|
// This is optional in case we add confidence types to prevent parse errors - backwards compatible.
|
|
|
|
optional Type type = 1;
|
2012-04-15 17:07:02 +00:00
|
|
|
|
|
|
|
// If type == BUILDING then this is the chain height at which the transaction was included.
|
2012-01-25 18:40:20 +00:00
|
|
|
optional int32 appeared_at_height = 2;
|
2012-04-15 17:07:02 +00:00
|
|
|
|
|
|
|
// If set, hash of the transaction that double spent this one into oblivion. A transaction can be double spent by
|
|
|
|
// multiple transactions in the case of several inputs being re-spent by several transactions but we don't
|
|
|
|
// bother to track them all, just the first. This only makes sense if type = OVERRIDDEN_BY_DOUBLE_SPEND.
|
|
|
|
optional bytes overriding_transaction = 3;
|
2012-01-25 18:40:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 18:43:15 +00:00
|
|
|
/** A bitcoin transaction */
|
|
|
|
|
2012-01-10 19:10:15 +00:00
|
|
|
message Transaction {
|
2012-01-12 00:29:09 +00:00
|
|
|
/**
|
|
|
|
* This is a bitfield oriented enum, with the following bits:
|
|
|
|
*
|
|
|
|
* bit 0 - spent
|
|
|
|
* bit 1 - appears in alt chain
|
|
|
|
* bit 2 - appears in best chain
|
|
|
|
* bit 3 - double-spent
|
|
|
|
* bit 4 - pending (we would like the tx to go into the best chain)
|
|
|
|
*
|
|
|
|
* Not all combinations are interesting, just the ones actually used in the enum.
|
|
|
|
*/
|
2012-01-10 19:10:15 +00:00
|
|
|
enum Pool {
|
2012-01-12 00:29:09 +00:00
|
|
|
UNSPENT = 4; // In best chain, not all outputs spent
|
|
|
|
SPENT = 5; // In best chain, all outputs spent
|
2012-01-11 18:04:00 +00:00
|
|
|
INACTIVE = 2; // In non-best chain, not our transaction
|
2012-01-12 00:29:09 +00:00
|
|
|
DEAD = 10; // Double-spent by a transaction in the best chain
|
2012-01-11 18:04:00 +00:00
|
|
|
PENDING = 16; // Our transaction, not in any chain
|
|
|
|
PENDING_INACTIVE = 18; // In non-best chain, our transaction
|
2012-01-06 22:50:34 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 19:01:12 +00:00
|
|
|
// See Wallet.java for detailed description of pool semantics
|
2012-01-10 19:10:15 +00:00
|
|
|
required int32 version = 1;
|
|
|
|
required bytes hash = 2;
|
2012-01-06 22:50:34 +00:00
|
|
|
|
2012-04-15 17:07:02 +00:00
|
|
|
// If pool is not present, that means either:
|
|
|
|
// - This Transaction is either not in a wallet at all (the proto is re-used elsewhere)
|
|
|
|
// - Or it is stored but for other purposes, for example, because it is the overriding transaction of a double spend.
|
|
|
|
// - Or the Pool enum got a new value which your software is too old to parse.
|
|
|
|
optional Pool pool = 3;
|
|
|
|
|
|
|
|
optional uint32 lock_time = 4; // The nLockTime field is useful for contracts.
|
2012-01-10 19:10:15 +00:00
|
|
|
optional int64 updated_at = 5; // millis since epoch the transaction was last updated
|
2012-01-06 22:50:34 +00:00
|
|
|
|
2012-01-10 19:10:15 +00:00
|
|
|
repeated TransactionInput transaction_input = 6;
|
|
|
|
repeated TransactionOutput transaction_output = 7;
|
2012-01-06 22:50:34 +00:00
|
|
|
|
2012-04-15 17:07:02 +00:00
|
|
|
// A list of blocks in which the transaction has been observed (on any chain).
|
2012-01-10 19:10:15 +00:00
|
|
|
repeated bytes block_hash = 8;
|
2012-01-25 18:40:20 +00:00
|
|
|
|
2012-04-15 17:07:02 +00:00
|
|
|
// Data describing where the transaction is in the chain.
|
2012-01-25 18:40:20 +00:00
|
|
|
optional TransactionConfidence confidence = 9;
|
2012-01-10 19:10:15 +00:00
|
|
|
}
|
2012-01-06 22:50:34 +00:00
|
|
|
|
2012-01-26 18:43:15 +00:00
|
|
|
/** An extension to the wallet */
|
2012-01-11 18:04:00 +00:00
|
|
|
message Extension {
|
|
|
|
required string id = 1; // like org.whatever.foo.bar
|
|
|
|
required bytes data = 2;
|
|
|
|
// If we do not understand a mandatory extension, abort to prevent data loss.
|
|
|
|
// For example, this could be applied to a new type of holding, such as a contract, where
|
|
|
|
// dropping of an extension in a read/write cycle could cause loss of value.
|
|
|
|
required bool mandatory = 3;
|
|
|
|
}
|
|
|
|
|
2012-01-26 18:43:15 +00:00
|
|
|
/** A bitcoin wallet */
|
2012-01-10 19:10:15 +00:00
|
|
|
message Wallet {
|
|
|
|
required string network_identifier = 1; // the network used by this wallet
|
|
|
|
// org.bitcoin.production = production network (Satoshi genesis block)
|
|
|
|
// org.bitcoin.test = test network (Andresen genesis block)
|
2012-01-06 22:50:34 +00:00
|
|
|
|
2012-04-15 17:07:02 +00:00
|
|
|
// The Sha256 hash of the head of the best chain seen by this wallet.
|
|
|
|
optional bytes last_seen_block_hash = 2;
|
2012-01-06 22:50:34 +00:00
|
|
|
|
2012-01-10 19:10:15 +00:00
|
|
|
repeated Key key = 3;
|
2012-01-11 18:04:00 +00:00
|
|
|
repeated Transaction transaction = 4;
|
|
|
|
repeated Extension extension = 10;
|
2012-01-06 22:50:34 +00:00
|
|
|
} // end of Wallet
|