Skip to content

Commit 6588860

Browse files
committed
[Model] WalletModel P2CS transactions connected.
1 parent e508ad0 commit 6588860

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/qt/walletmodel.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,30 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
351351
setAddress.insert(rcp.address);
352352
++nAddresses;
353353

354-
CScript scriptPubKey = GetScriptForDestination(CBitcoinAddress(rcp.address.toStdString()).Get());
354+
CScript scriptPubKey;
355+
CBitcoinAddress out = CBitcoinAddress(rcp.address.toStdString());
356+
357+
if (rcp.isP2CS) {
358+
CBitcoinAddress ownerAdd;
359+
if (rcp.ownerAddress.isEmpty()) {
360+
// Create new internal owner address
361+
if (!getNewAddress(ownerAdd).result)
362+
return CannotCreateInternalAddress;
363+
} else {
364+
ownerAdd = CBitcoinAddress(rcp.ownerAddress.toStdString());
365+
}
366+
367+
CKeyID stakerId;
368+
CKeyID ownerId;
369+
if(!out.GetKeyID(stakerId) || !ownerAdd.GetKeyID(ownerId)) {
370+
return InvalidAddress;
371+
}
372+
373+
scriptPubKey = GetScriptForStakeDelegation(stakerId, ownerId);
374+
} else {
375+
// Regular P2PK or P2PKH
376+
scriptPubKey = GetScriptForDestination(out.Get());
377+
}
355378
vecSend.push_back(std::pair<CScript, CAmount>(scriptPubKey, rcp.amount));
356379

357380
total += rcp.amount;
@@ -418,9 +441,11 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction& tran
418441
return AnonymizeOnlyUnlocked;
419442
}
420443

444+
bool fColdStakingActive = sporkManager.IsSporkActive(SPORK_17_COLDSTAKING_ENFORCEMENT);
445+
421446
// Double check tx before do anything
422447
CValidationState state;
423-
if(!CheckTransaction(*transaction.getTransaction(), true, true, state, true)){
448+
if(!CheckTransaction(*transaction.getTransaction(), true, true, state, true, fColdStakingActive)){
424449
return TransactionCommitFailed;
425450
}
426451

src/qt/walletmodel.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class SendCoinsRecipient
5454
QString label;
5555
AvailableCoinsType inputType;
5656
bool useSwiftTX = false;
57+
58+
// Cold staking.
59+
bool isP2CS = false;
60+
QString ownerAddress;
61+
62+
// Amount
5763
CAmount amount;
5864
// If from a payment request, this is used for storing the memo
5965
QString message;
@@ -119,7 +125,8 @@ class WalletModel : public QObject
119125
TransactionCreationFailed, // Error returned when wallet is still locked
120126
TransactionCommitFailed,
121127
AnonymizeOnlyUnlocked,
122-
InsaneFee
128+
InsaneFee,
129+
CannotCreateInternalAddress
123130
};
124131

125132
enum EncryptionStatus {
@@ -210,6 +217,18 @@ class WalletModel : public QObject
210217
CZerocoinSpendReceipt &receipt
211218
);
212219

220+
// ###################
221+
// Cold Staking
222+
// ###################
223+
224+
225+
226+
// ###################
227+
// End Cold Staking
228+
// ###################
229+
230+
231+
213232
// Wallet encryption
214233
bool setWalletEncrypted(bool encrypted, const SecureString& passphrase);
215234
// Passphrase only needed when unlocking

0 commit comments

Comments
 (0)