@@ -518,7 +518,6 @@ impl Block {
518
518
pub fn weight ( & self ) -> u32 {
519
519
self . dr_weight ( ) + self . vt_weight ( ) + self . st_weight ( )
520
520
}
521
-
522
521
}
523
522
524
523
impl BlockTransactions {
@@ -1370,6 +1369,18 @@ pub struct ValueTransferOutput {
1370
1369
pub time_lock : u64 ,
1371
1370
}
1372
1371
1372
+ impl ValueTransferOutput {
1373
+ #[ inline]
1374
+ pub fn value ( & self ) -> u64 {
1375
+ self . value
1376
+ }
1377
+
1378
+ #[ inline]
1379
+ pub fn weight ( & self ) -> u32 {
1380
+ OUTPUT_SIZE
1381
+ }
1382
+ }
1383
+
1373
1384
/// Data request output transaction data structure
1374
1385
#[ derive( Debug , Eq , PartialEq , Clone , Serialize , Deserialize , ProtobufConvert , Hash , Default ) ]
1375
1386
#[ protobuf_convert( pb = "witnet::DataRequestOutput" ) ]
@@ -1436,6 +1447,44 @@ impl DataRequestOutput {
1436
1447
}
1437
1448
}
1438
1449
1450
+ #[ derive( Debug , Default , Eq , PartialEq , Clone , Serialize , Deserialize , ProtobufConvert , Hash ) ]
1451
+ #[ protobuf_convert( pb = "witnet::StakeOutput" ) ]
1452
+ pub struct StakeOutput {
1453
+ pub value : u64 ,
1454
+ pub authorization : KeyedSignature ,
1455
+ }
1456
+
1457
+ impl StakeOutput {
1458
+ #[ inline]
1459
+ pub fn weight ( & self ) -> u32 {
1460
+ crate :: transaction:: STAKE_OUTPUT_WEIGHT
1461
+ }
1462
+ }
1463
+
1464
+ pub enum Output {
1465
+ DataRequest ( DataRequestOutput ) ,
1466
+ Stake ( StakeOutput ) ,
1467
+ ValueTransfer ( ValueTransferOutput ) ,
1468
+ }
1469
+
1470
+ impl Output {
1471
+ pub fn value ( & self ) -> Result < u64 , TransactionError > {
1472
+ match self {
1473
+ Output :: DataRequest ( output) => output. checked_total_value ( ) ,
1474
+ Output :: Stake ( output) => Ok ( output. value ) ,
1475
+ Output :: ValueTransfer ( output) => Ok ( output. value ) ,
1476
+ }
1477
+ }
1478
+
1479
+ pub fn weight ( & self ) -> u32 {
1480
+ match self {
1481
+ Output :: DataRequest ( output) => output. weight ( ) ,
1482
+ Output :: Stake ( output) => output. weight ( ) ,
1483
+ Output :: ValueTransfer ( output) => output. weight ( ) ,
1484
+ }
1485
+ }
1486
+ }
1487
+
1439
1488
/// Information about the total supply
1440
1489
#[ derive( Clone , Debug , Serialize , Deserialize ) ]
1441
1490
pub struct SupplyInfo {
@@ -2761,8 +2810,7 @@ impl TransactionsPool {
2761
2810
/// Returns a list of all the removed transactions.
2762
2811
fn remove_transactions_for_size_limit ( & mut self ) -> Vec < Transaction > {
2763
2812
let mut removed_transactions = vec ! [ ] ;
2764
- while self . total_transactions_weight ( ) > self . weight_limit
2765
- {
2813
+ while self . total_transactions_weight ( ) > self . weight_limit {
2766
2814
// Try to split the memory between value transfer and data requests using the same
2767
2815
// ratio as the one used in blocks
2768
2816
// The ratio of vt to dr in blocks is currently 1:4
@@ -3107,8 +3155,8 @@ impl TransactionsPool {
3107
3155
v
3108
3156
}
3109
3157
3110
- pub fn total_transactions_weight ( & self ) -> u64 {
3111
- self . total_vt_weight + self . total_dr_weight + self . total_st_weight
3158
+ pub fn total_transactions_weight ( & self ) -> u64 {
3159
+ self . total_vt_weight + self . total_dr_weight + self . total_st_weight
3112
3160
}
3113
3161
}
3114
3162
@@ -4218,7 +4266,7 @@ pub fn transaction_example() -> Transaction {
4218
4266
let outputs = vec ! [ value_transfer_output] ;
4219
4267
4220
4268
Transaction :: DataRequest ( DRTransaction :: new (
4221
- DRTransactionBody :: new ( inputs, outputs , data_request_output ) ,
4269
+ DRTransactionBody :: new ( inputs, data_request_output , outputs ) ,
4222
4270
keyed_signature,
4223
4271
) )
4224
4272
}
@@ -4322,7 +4370,7 @@ mod tests {
4322
4370
. iter ( )
4323
4371
. map ( |input| {
4324
4372
DRTransaction :: new (
4325
- DRTransactionBody :: new ( vec ! [ * input] , vec ! [ ] , DataRequestOutput :: default ( ) ) ,
4373
+ DRTransactionBody :: new ( vec ! [ * input] , DataRequestOutput :: default ( ) , vec ! [ ] ) ,
4326
4374
vec ! [ ] ,
4327
4375
)
4328
4376
} )
@@ -4796,14 +4844,14 @@ mod tests {
4796
4844
) ;
4797
4845
4798
4846
let dr_1 = DRTransaction :: new (
4799
- DRTransactionBody :: new ( vec ! [ input] , vec ! [ ] , DataRequestOutput :: default ( ) ) ,
4847
+ DRTransactionBody :: new ( vec ! [ input] , DataRequestOutput :: default ( ) , vec ! [ ] ) ,
4800
4848
vec ! [ ] ,
4801
4849
) ;
4802
4850
let dr_2 = DRTransaction :: new (
4803
4851
DRTransactionBody :: new (
4804
4852
vec ! [ input] ,
4805
- vec ! [ ValueTransferOutput :: default ( ) ] ,
4806
4853
DataRequestOutput :: default ( ) ,
4854
+ vec ! [ ValueTransferOutput :: default ( ) ] ,
4807
4855
) ,
4808
4856
vec ! [ ] ,
4809
4857
) ;
@@ -4873,14 +4921,14 @@ mod tests {
4873
4921
) ;
4874
4922
4875
4923
let dr_1 = DRTransaction :: new (
4876
- DRTransactionBody :: new ( vec ! [ input] , vec ! [ ] , DataRequestOutput :: default ( ) ) ,
4924
+ DRTransactionBody :: new ( vec ! [ input] , DataRequestOutput :: default ( ) , vec ! [ ] ) ,
4877
4925
vec ! [ ] ,
4878
4926
) ;
4879
4927
let dr_2 = DRTransaction :: new (
4880
4928
DRTransactionBody :: new (
4881
4929
vec ! [ input2] ,
4882
- vec ! [ ValueTransferOutput :: default ( ) ] ,
4883
4930
DataRequestOutput :: default ( ) ,
4931
+ vec ! [ ValueTransferOutput :: default ( ) ] ,
4884
4932
) ,
4885
4933
vec ! [ ] ,
4886
4934
) ;
@@ -4974,11 +5022,11 @@ mod tests {
4974
5022
assert_ne ! ( input0, input1) ;
4975
5023
4976
5024
let dr_1 = DRTransaction :: new (
4977
- DRTransactionBody :: new ( vec ! [ input0] , vec ! [ ] , DataRequestOutput :: default ( ) ) ,
5025
+ DRTransactionBody :: new ( vec ! [ input0] , DataRequestOutput :: default ( ) , vec ! [ ] ) ,
4978
5026
vec ! [ ] ,
4979
5027
) ;
4980
5028
let dr_2 = DRTransaction :: new (
4981
- DRTransactionBody :: new ( vec ! [ input0, input1] , vec ! [ ] , DataRequestOutput :: default ( ) ) ,
5029
+ DRTransactionBody :: new ( vec ! [ input0, input1] , DataRequestOutput :: default ( ) , vec ! [ ] ) ,
4982
5030
vec ! [ ] ,
4983
5031
) ;
4984
5032
@@ -5040,7 +5088,7 @@ mod tests {
5040
5088
fn transactions_pool_malleability_dr ( ) {
5041
5089
let input = Input :: default ( ) ;
5042
5090
let mut dr_1 = DRTransaction :: new (
5043
- DRTransactionBody :: new ( vec ! [ input] , vec ! [ ] , DataRequestOutput :: default ( ) ) ,
5091
+ DRTransactionBody :: new ( vec ! [ input] , DataRequestOutput :: default ( ) , vec ! [ ] ) ,
5044
5092
vec ! [ KeyedSignature :: default ( ) ] ,
5045
5093
) ;
5046
5094
// Add dummy signature, but pretend it is valid
@@ -5235,12 +5283,12 @@ mod tests {
5235
5283
Transaction :: DataRequest ( DRTransaction :: new (
5236
5284
DRTransactionBody :: new (
5237
5285
vec ! [ Input :: default ( ) ] ,
5286
+ DataRequestOutput :: default ( ) ,
5238
5287
vec ! [ ValueTransferOutput {
5239
5288
pkh: Default :: default ( ) ,
5240
5289
value: i,
5241
5290
time_lock: 0 ,
5242
5291
} ] ,
5243
- DataRequestOutput :: default ( ) ,
5244
5292
) ,
5245
5293
vec ! [ ] ,
5246
5294
) )
@@ -5478,7 +5526,7 @@ mod tests {
5478
5526
witnesses : 1 ,
5479
5527
..Default :: default ( )
5480
5528
} ;
5481
- let drb = DRTransactionBody :: new ( vec ! [ ] , vec ! [ ] , dro ) ;
5529
+ let drb = DRTransactionBody :: new ( vec ! [ ] , dro , vec ! [ ] ) ;
5482
5530
let drt = DRTransaction :: new (
5483
5531
drb,
5484
5532
vec ! [ KeyedSignature {
@@ -5516,7 +5564,7 @@ mod tests {
5516
5564
commit_and_reveal_fee : 501 ,
5517
5565
..Default :: default ( )
5518
5566
} ;
5519
- let drb1 = DRTransactionBody :: new ( vec ! [ ] , vec ! [ ] , dro1 ) ;
5567
+ let drb1 = DRTransactionBody :: new ( vec ! [ ] , dro1 , vec ! [ ] ) ;
5520
5568
let drt1 = DRTransaction :: new (
5521
5569
drb1,
5522
5570
vec ! [ KeyedSignature {
@@ -5531,7 +5579,7 @@ mod tests {
5531
5579
commit_and_reveal_fee : 100 ,
5532
5580
..Default :: default ( )
5533
5581
} ;
5534
- let drb2 = DRTransactionBody :: new ( vec ! [ ] , vec ! [ ] , dro2 ) ;
5582
+ let drb2 = DRTransactionBody :: new ( vec ! [ ] , dro2 , vec ! [ ] ) ;
5535
5583
let drt2 = DRTransaction :: new (
5536
5584
drb2,
5537
5585
vec ! [ KeyedSignature {
@@ -5546,7 +5594,7 @@ mod tests {
5546
5594
commit_and_reveal_fee : 500 ,
5547
5595
..Default :: default ( )
5548
5596
} ;
5549
- let drb3 = DRTransactionBody :: new ( vec ! [ ] , vec ! [ ] , dro3 ) ;
5597
+ let drb3 = DRTransactionBody :: new ( vec ! [ ] , dro3 , vec ! [ ] ) ;
5550
5598
let drt3 = DRTransaction :: new (
5551
5599
drb3,
5552
5600
vec ! [ KeyedSignature {
@@ -5638,7 +5686,7 @@ mod tests {
5638
5686
witnesses : 2 ,
5639
5687
..Default :: default ( )
5640
5688
} ;
5641
- let drb = DRTransactionBody :: new ( vec ! [ ] , vec ! [ ] , dro ) ;
5689
+ let drb = DRTransactionBody :: new ( vec ! [ ] , dro , vec ! [ ] ) ;
5642
5690
let drt = DRTransaction :: new (
5643
5691
drb,
5644
5692
vec ! [ KeyedSignature {
@@ -5678,7 +5726,7 @@ mod tests {
5678
5726
witnesses : 1 ,
5679
5727
..Default :: default ( )
5680
5728
} ;
5681
- let drb = DRTransactionBody :: new ( vec ! [ ] , vec ! [ ] , dro ) ;
5729
+ let drb = DRTransactionBody :: new ( vec ! [ ] , dro , vec ! [ ] ) ;
5682
5730
let drt = DRTransaction :: new (
5683
5731
drb,
5684
5732
vec ! [ KeyedSignature {
@@ -5717,7 +5765,7 @@ mod tests {
5717
5765
witnesses : 1 ,
5718
5766
..Default :: default ( )
5719
5767
} ;
5720
- let drb = DRTransactionBody :: new ( vec ! [ ] , vec ! [ ] , dro ) ;
5768
+ let drb = DRTransactionBody :: new ( vec ! [ ] , dro , vec ! [ ] ) ;
5721
5769
let drt = DRTransaction :: new (
5722
5770
drb,
5723
5771
vec ! [ KeyedSignature {
@@ -5755,7 +5803,7 @@ mod tests {
5755
5803
witnesses : 2 ,
5756
5804
..Default :: default ( )
5757
5805
} ;
5758
- let drb = DRTransactionBody :: new ( vec ! [ ] , vec ! [ ] , dro ) ;
5806
+ let drb = DRTransactionBody :: new ( vec ! [ ] , dro , vec ! [ ] ) ;
5759
5807
let drt = DRTransaction :: new (
5760
5808
drb,
5761
5809
vec ! [ KeyedSignature {
@@ -5793,7 +5841,7 @@ mod tests {
5793
5841
witnesses : 2 ,
5794
5842
..Default :: default ( )
5795
5843
} ;
5796
- let drb = DRTransactionBody :: new ( vec ! [ ] , vec ! [ ] , dro ) ;
5844
+ let drb = DRTransactionBody :: new ( vec ! [ ] , dro , vec ! [ ] ) ;
5797
5845
let drt = DRTransaction :: new (
5798
5846
drb,
5799
5847
vec ! [ KeyedSignature {
0 commit comments