Files
pay/Wallet_p.h
T

161 lines
5.3 KiB
C++
Raw Permalink Normal View History

2020-10-17 16:38:37 +02:00
/*
* This file is part of the Flowee project
2021-04-21 15:17:08 +02:00
* Copyright (C) 2020-2021 Tom Zander <tom@flowee.org>
2020-10-17 16:38:37 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WALLET_P_H
#define WALLET_P_H
2020-10-17 16:38:37 +02:00
#include <BroadcastTxData.h>
2020-10-17 16:38:37 +02:00
#include <QObject>
2020-10-17 16:38:37 +02:00
#include <QSet>
#include <deque>
#include <vector>
class Wallet;
2020-10-17 16:38:37 +02:00
2021-10-29 12:48:12 +02:00
/*
* Fee estimation needs to know how much space is used per input.
* 32 + 4 for the prevTx
* Then 72 + 33 bytes for the signature and pub-key (+-1).
* Using schnorr we can gain 8 bytes for the signature (not included here).
*/
constexpr int BYTES_PER_OUTPUT = 149;
/// Reject any solution with > this amount of inputs as that will result in > 100.000 byte transactions
constexpr int MAX_INPUTS = 670;
constexpr int MATURATION_AGE = 100; //< the amount of blocks a coinbase takes before we can spend it
2021-10-29 12:48:12 +02:00
2020-10-17 16:38:37 +02:00
namespace WalletPriv
{
// we may have transactions that spend outputs created within the same block.
// this method will make sure that we sort them so those that spend others
// are sorted after the ones they spent.
std::deque<Tx> sortTransactions(const std::deque<Tx> &in);
2020-11-06 20:05:42 +01:00
enum PrivateSaveTags {
Separator = 0,
Index,
PrivKey,
PrivKeyEncrypted,
PubKeyHash,
HeightCreated, // for an address / privkey this is used to check which blocks to query
2021-04-21 15:17:08 +02:00
IsSingleAddressWallet, // bool
UserOwnedWallet, // bool (defaults to true)
2021-05-04 17:41:49 +02:00
SignatureType, // See the enum Wallet::WalletSecret::SignatureType
2021-10-21 14:57:20 +02:00
// Wallet-wide HD settings.
HDWalletMnemonic, // string
HDWalletMnemonicPassword, // string
HDWalletPathItem, // int, one part of the derivation path. (typically 5 are give in a row)
2021-10-21 14:57:20 +02:00
HDWalletLastChangeIndex, // In the 'change' derivation, which private key did we create last.
HDWalletLastReceiveIndex, // In the 'main' derivation, which private key did we create last.
// Per-privkey HD settings.
HDKeyFromChangeChain, // bool. If true, this privkey comes from the 'change' derivation chain. (before last field in derivation path)
HDKeyDerivationIndex, // int, the index used to generate this key (last field in derivation path)
2021-11-02 14:24:47 +01:00
// Versioning
WalletVersion, // int.
2020-11-06 20:05:42 +01:00
};
2020-11-06 20:05:42 +01:00
enum WalletDataSaveTags {
// Separator = 0
// Index = 1
LastSynchedBlock = 2,
WalletName,
// per tx-data
TxId = 10,
BlockHash,
BlockHeight,
InputIndex,
2020-11-06 20:05:42 +01:00
InputSpendsTx, // int that refers to index of the WTX it spends
InputSpendsOutput, // input that refers to the output in the WTX it spends
/// Used after InputIndex to mark the lock-state of an input.
2021-05-03 12:40:48 +02:00
OutputLockState, // positive number, see OutputLockStateEnum
OutputLockAutoSpender, // the tx that locked an output (index in m_walletTransactions
2020-11-06 20:05:42 +01:00
// per tx metadata
UserComment, // string
2020-11-06 20:05:42 +01:00
OutputIndex = 30,
OutputValue, // in Satoshi
OutputFromCoinbase, // bool
KeyStoreIndex, // int that refers to the index of the privkey for the current tx-output.
2021-11-16 15:01:02 +01:00
TxIsCashFusion, // bool
2021-01-06 23:15:54 +01:00
// PaymentRequests
PaymentRequestType = 40, // int, BIP21 or other
PaymentRequestAddress, // int, the ID of the private-key
PaymentRequestMessage, // string
PaymentRequestAmount, // long, num satoshis
PaymentRequestOldAddress, // bool (default false)
PaymentRequestPaid, // long, num satoshis received
PaymentRequestTxIndex, // int, index in m_walletTransactions
PaymentRequestOutputIndex, // int. Together with prev makes an OutputRef
2021-01-06 23:15:54 +01:00
};
2021-05-03 12:40:48 +02:00
enum OutputLockStateEnum {
Unlocked = 0, // default value when not saved
AutoLocked, // Locked due to it being spent. Locked until mined.
UserLocked // User locked this output
};
enum SpecialBlockHeight {
Genesis = 0,
Unconfirmed = -1, // a tx marked with this height is waiting to get confirmed
Rejected = -2 // a tx marked with this height can no longer be mined
};
}
// this is used to broadcast transactions
// see ConnectionManager::broadcastTransaction()
class WalletInfoObject : public QObject, public BroadcastTxData
{
Q_OBJECT
public:
WalletInfoObject(Wallet *parent, int txIndex, const Tx &tx);
void txRejected(RejectReason reason, const std::string &message);
void sentOne();
uint16_t privSegment() const;
int txIndex() const;
private slots:
// scheduled from a non-Qt thread to start a timer.
void startCheckState();
// called 5 seonds after every request from a peer for data
void checkState();
signals:
void finished(int txIndex, bool success);
private:
const Wallet *m_wallet;
const int m_txIndex;
short m_sentPeerCount = 0;
short m_rejectedPeerCount = 0;
2020-10-17 16:38:37 +02:00
};
#endif