Skip to content

Commit ee2121e

Browse files
committed
Add OutputValue::TokenV1
1 parent 183a2d3 commit ee2121e

File tree

14 files changed

+40
-34
lines changed

14 files changed

+40
-34
lines changed

chainstate/src/detail/chainstateref/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
739739
}
740740

741741
fn check_tokens_txs(&self, block: &Block) -> Result<(), CheckBlockTransactionsError> {
742+
// FIXME: check tokens versions
742743
for tx in block.transactions() {
743744
// We can't issue multiple tokens in a single tx
744745
let issuance_count = get_tokens_issuance_count(tx.outputs());

chainstate/test-framework/src/utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub fn create_utxo_data(
109109
new_token_transfer_output(chainstate, &outsrc, Amount::from_atoms(1))
110110
}
111111
},
112+
OutputValue::TokenV1(_) => todo!(),
112113
};
113114

114115
Some((
@@ -236,6 +237,7 @@ pub fn create_multiple_utxo_data(
236237
}
237238
}
238239
},
240+
OutputValue::TokenV1(_) => todo!(),
239241
};
240242

241243
Some((

chainstate/test-suite/src/tests/fungible_tokens.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,6 @@ fn token_issuance_with_insufficient_fee(#[case] seed: Seed) {
791791
})
792792
}
793793

794-
// FIXME: token_reissuance_with_insufficient_fee
795-
796794
#[rstest]
797795
#[trace]
798796
#[case(Seed::from_entropy())]

chainstate/test-suite/src/tests/fungible_tokens_v1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,6 @@ fn token_issue_test(#[case] seed: Seed) {
245245
// FIXME: check that token account was created
246246
});
247247
}
248+
249+
// FIXME: more tests
250+
// FIXME: token_reissuance_with_insufficient_fee

chainstate/tx-verifier/src/transaction_verifier/input_output_policy/constraints_accumulator.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,13 @@ impl ConstrainedValueAccumulator {
162162
IOPolicyError::AttemptToPrintMoneyOrViolateTimelockConstraints,
163163
)?;
164164
}
165-
OutputValue::Token(token_data) => match token_data.as_ref() {
166-
TokenData::TokenTransfer(data) => {
167-
if let Some(constrained_amount) =
168-
self.burn_constrained.get_mut(&data.token_id)
169-
{
170-
*constrained_amount = (*constrained_amount - data.amount)
171-
.ok_or(IOPolicyError::AmountOverflow)?;
172-
}
173-
}
174-
TokenData::TokenIssuance(_) | TokenData::NftIssuance(_) => {
175-
todo!("this has to handle TokenV1??")
165+
OutputValue::Token(_) => { /* do nothing */ }
166+
OutputValue::TokenV1((id, value)) => {
167+
if let Some(constrained_amount) = self.burn_constrained.get_mut(id) {
168+
*constrained_amount = (*constrained_amount - *value)
169+
.ok_or(IOPolicyError::AmountOverflow)?;
176170
}
177-
},
171+
}
178172
},
179173
TxOutput::DelegateStaking(coins, _) => {
180174
self.unconstrained_value = (self.unconstrained_value - *coins)

chainstate/tx-verifier/src/transaction_verifier/transferred_amount_check.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ fn get_output_token_id_and_amount(
242242
None => None,
243243
},
244244
},
245+
OutputValue::TokenV1((id, amount)) => Some((CoinOrTokenId::TokenId(*id), *amount)),
245246
})
246247
}
247248

@@ -270,6 +271,7 @@ where
270271
TokensError::TokenIdCantBeCalculated,
271272
)),
272273
},
274+
OutputValue::TokenV1((id, amount)) => Ok((CoinOrTokenId::TokenId(*id), *amount)),
273275
}
274276
}
275277

common/src/chain/tokens/tokens_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn get_tokens_issuance_v0_count(outputs: &[TxOutput]) -> usize {
5353
TokenData::TokenIssuance(_) | TokenData::NftIssuance(_) => true,
5454
TokenData::TokenTransfer(_) => false,
5555
},
56-
OutputValue::Coin(_) => false,
56+
OutputValue::Coin(_) | OutputValue::TokenV1(_) => false,
5757
}
5858
}
5959
TxOutput::CreateStakePool(_, _)
@@ -88,7 +88,7 @@ pub fn is_token_or_nft_issuance(output: &TxOutput) -> bool {
8888
TokenData::TokenIssuance(_) | TokenData::NftIssuance(_) => true,
8989
TokenData::TokenTransfer(_) => false,
9090
},
91-
OutputValue::Coin(_) => false,
91+
OutputValue::Coin(_) | OutputValue::TokenV1(_) => false,
9292
}
9393
}
9494
TxOutput::TokenIssuance(_) => true,

common/src/chain/transaction/output/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub enum TxOutput {
9292
DelegateStaking(Amount, DelegationId),
9393
#[codec(index = 7)]
9494
TokenIssuance(Box<TokenIssuanceVersioned>),
95+
// FIXME: add NftIssuance at once?
9596
}
9697

9798
impl TxOutput {

common/src/chain/transaction/output/output_value.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@
1616
use serialization::{Decode, Encode};
1717

1818
use crate::{
19-
chain::tokens::{NftIssuance, TokenData, TokenIssuance, TokenTransfer},
19+
chain::tokens::{NftIssuance, TokenData, TokenId, TokenIssuance, TokenTransfer},
2020
primitives::Amount,
2121
};
2222

2323
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, serde::Serialize)]
2424
pub enum OutputValue {
2525
Coin(Amount),
26-
Token(Box<TokenData>),
27-
// FIXME: add TokenV1 with just amount
26+
Token(Box<TokenData>), // FIXME: add check that this type is not used after upgrade
27+
TokenV1((TokenId, Amount)),
2828
}
2929

3030
impl OutputValue {
3131
pub fn coin_amount(&self) -> Option<Amount> {
3232
match self {
3333
OutputValue::Coin(v) => Some(*v),
34-
OutputValue::Token(_) => None,
34+
OutputValue::Token(_) | OutputValue::TokenV1(_) => None,
3535
}
3636
}
3737

3838
pub fn token_data(&self) -> Option<&TokenData> {
3939
match self {
40-
OutputValue::Coin(_) => None,
40+
OutputValue::Coin(_) | OutputValue::TokenV1(_) => None,
4141
OutputValue::Token(d) => Some(d),
4242
}
4343
}

common/src/chain/transaction/signature/tests/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ fn add_value(output_value: OutputValue) -> OutputValue {
711711
match output_value {
712712
OutputValue::Coin(v) => OutputValue::Coin((v + Amount::from_atoms(100)).unwrap()),
713713
OutputValue::Token(v) => OutputValue::Token(v),
714+
OutputValue::TokenV1((d, v)) => {
715+
OutputValue::TokenV1((d, (v + Amount::from_atoms(100)).unwrap()))
716+
}
714717
}
715718
}
716719

common/src/chain/transaction/signature/tests/sign_and_mutate.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ use itertools::Itertools;
1717
use rstest::rstest;
1818
use test_utils::random::Seed;
1919

20-
use super::utils::*;
20+
use super::{add_value, utils::*};
2121
use crate::{
2222
chain::{
2323
config::create_mainnet,
24-
output_value::OutputValue,
2524
signature::{
2625
sighash::sighashtype::{OutputsMode, SigHashType},
2726
tests::{
@@ -1059,13 +1058,6 @@ fn add_output(_rng: &mut impl Rng, tx: &SignedTransactionWithUtxo) -> SignedTran
10591058
}
10601059
}
10611060

1062-
fn add_value(output_value: OutputValue) -> OutputValue {
1063-
match output_value {
1064-
OutputValue::Coin(v) => OutputValue::Coin((v + Amount::from_atoms(100)).unwrap()),
1065-
OutputValue::Token(v) => OutputValue::Token(v),
1066-
}
1067-
}
1068-
10691061
fn mutate_output(_rng: &mut impl Rng, tx: &SignedTransactionWithUtxo) -> SignedTransactionWithUtxo {
10701062
let mut updater = MutableTransaction::from(&tx.tx);
10711063
// Should fail due to change in output value

mempool/src/pool/tests/utils.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ fn output_coin_amount(output: &TxOutput) -> Amount {
199199
TxOutput::LockThenTransfer(val, _, _) => val,
200200
_ => return Amount::ZERO,
201201
};
202-
match val {
203-
OutputValue::Coin(amt) => *amt,
204-
OutputValue::Token(_) => Amount::ZERO,
205-
}
202+
val.coin_amount().unwrap_or(Amount::ZERO)
206203
}
207204

208205
pub fn make_tx(

wallet/src/account/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,12 @@ fn group_outputs<T, Grouped: Clone>(
12141214
TokenData::TokenIssuance(_) | TokenData::NftIssuance(_) => {}
12151215
}
12161216
}
1217+
OutputValue::TokenV1((id, amount)) => {
1218+
let total_token_amount =
1219+
tokens_grouped.entry(Currency::Token(id)).or_insert_with(|| init.clone());
1220+
1221+
combiner(total_token_amount, &output, amount)?;
1222+
}
12171223
}
12181224
}
12191225

@@ -1280,6 +1286,12 @@ fn group_utxos_for_input<T, Grouped: Clone>(
12801286
}
12811287
}
12821288
}
1289+
OutputValue::TokenV1((id, amount)) => {
1290+
let total_token_amount =
1291+
tokens_grouped.entry(Currency::Token(id)).or_insert_with(|| init.clone());
1292+
1293+
combiner(total_token_amount, &output, amount)?;
1294+
}
12831295
}
12841296
}
12851297

wallet/src/account/utxo_selector/output_group.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl OutputGroup {
7777
TokenData::NftIssuance(_) => Amount::from_atoms(1),
7878
}
7979
}
80+
OutputValue::TokenV1((_, output_amount)) => output_amount,
8081
};
8182

8283
Ok(Self {

0 commit comments

Comments
 (0)