Skip to content

Commit 5690229

Browse files
feat(platform)!: token payment info (#2517)
1 parent 3d9b08d commit 5690229

132 files changed

Lines changed: 5068 additions & 1000 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,50 @@
287287
}
288288
}
289289
]
290+
},
291+
"documentActionTokenCost": {
292+
"type": "object",
293+
"properties": {
294+
"contractId": {
295+
"type": "array",
296+
"contentMediaType": "application/x.dash.dpp.identifier",
297+
"byteArray": true,
298+
"minItems": 32,
299+
"maxItems": 32
300+
},
301+
"tokenPosition": {
302+
"type": "integer",
303+
"minimum": 0,
304+
"maximum": 65535
305+
},
306+
"amount": {
307+
"type": "integer",
308+
"minimum": 1,
309+
"maximum": 281474976710655
310+
},
311+
"effect": {
312+
"type": "integer",
313+
"enum": [
314+
0,
315+
1
316+
],
317+
"description": "0 - TransferTokenToContractOwner (default), 1 - Burn"
318+
},
319+
"gasFeesPaidBy": {
320+
"type": "integer",
321+
"enum": [
322+
0,
323+
1,
324+
2
325+
],
326+
"description": "0 - DocumentOwner (default), 1 - ContractOwner, 2 - PreferContractOwner"
327+
}
328+
},
329+
"required": [
330+
"tokenPosition",
331+
"amount"
332+
],
333+
"additionalProperties": false
290334
}
291335
},
292336
"properties": {
@@ -453,6 +497,30 @@
453497
],
454498
"description": "Key requirements. 0 - Unique Non Replaceable, 1 - Multiple, 2 - Multiple with reference to latest key."
455499
},
500+
"tokenCost": {
501+
"type": "object",
502+
"properties": {
503+
"create": {
504+
"$ref": "#/$defs/documentActionTokenCost"
505+
},
506+
"replace": {
507+
"$ref": "#/$defs/documentActionTokenCost"
508+
},
509+
"delete": {
510+
"$ref": "#/$defs/documentActionTokenCost"
511+
},
512+
"transfer": {
513+
"$ref": "#/$defs/documentActionTokenCost"
514+
},
515+
"update_price": {
516+
"$ref": "#/$defs/documentActionTokenCost"
517+
},
518+
"purchase": {
519+
"$ref": "#/$defs/documentActionTokenCost"
520+
}
521+
},
522+
"additionalProperties": false
523+
},
456524
"properties": {
457525
"type": "object",
458526
"additionalProperties": {

packages/rs-dpp/src/core_types/validator_set/v0/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use bincode::error::EncodeError;
99
#[cfg(feature = "core-types-serialization")]
1010
use bincode::{BorrowDecode, Decode, Encode};
1111
use dashcore::blsful::Bls12381G2Impl;
12+
#[cfg(feature = "core-types-serialization")]
1213
use dashcore::hashes::Hash;
1314
use dashcore::{ProTxHash, QuorumHash};
1415
use itertools::Itertools;
@@ -18,7 +19,7 @@ use std::collections::BTreeMap;
1819
use std::fmt;
1920
use std::fmt::{Debug, Display, Formatter};
2021

21-
/// The validator set is only slightly different from a quorum as it does not contain non valid
22+
/// The validator set is only slightly different from a quorum as it does not contain non-valid
2223
/// members
2324
#[derive(Clone, Eq, PartialEq)]
2425
#[cfg_attr(

packages/rs-dpp/src/data_contract/document_type/accessors/mod.rs

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,28 @@ use crate::data_contract::document_type::{DocumentType, DocumentTypeMutRef, Docu
88

99
use platform_value::{Identifier, Value};
1010

11-
use crate::balances::credits::TokenAmount;
1211
use crate::data_contract::document_type::restricted_creation::CreationRestrictionMode;
1312
#[cfg(feature = "validation")]
1413
use crate::data_contract::document_type::validator::StatelessJsonSchemaLazyValidator;
1514
use crate::data_contract::storage_requirements::keys_for_document_type::StorageKeyRequirements;
16-
use crate::data_contract::TokenContractPosition;
1715
use crate::document::transfer::Transferable;
1816
use crate::identity::SecurityLevel;
1917
use crate::nft::TradeMode;
18+
use crate::tokens::token_amount_on_contract_token::DocumentActionTokenCost;
2019
use indexmap::IndexMap;
2120
use std::collections::{BTreeMap, BTreeSet};
2221
pub use v0::*;
2322
pub use v1::*;
2423

24+
impl DocumentTypeV0MutGetters for DocumentType {
25+
fn schema_mut(&mut self) -> &mut Value {
26+
match self {
27+
DocumentType::V0(v0) => v0.schema_mut(),
28+
DocumentType::V1(v1) => v1.schema_mut(),
29+
}
30+
}
31+
}
32+
2533
impl DocumentTypeV0Getters for DocumentType {
2634
fn name(&self) -> &String {
2735
match self {
@@ -195,6 +203,50 @@ impl DocumentTypeV0Setters for DocumentType {
195203
}
196204
}
197205

206+
impl DocumentTypeV1Setters for DocumentType {
207+
fn set_document_creation_token_cost(&mut self, cost: Option<DocumentActionTokenCost>) {
208+
match self {
209+
DocumentType::V0(_) => { /* no-op */ }
210+
DocumentType::V1(v1) => v1.set_document_creation_token_cost(cost),
211+
}
212+
}
213+
214+
fn set_document_replacement_token_cost(&mut self, cost: Option<DocumentActionTokenCost>) {
215+
match self {
216+
DocumentType::V0(_) => { /* no-op */ }
217+
DocumentType::V1(v1) => v1.set_document_replacement_token_cost(cost),
218+
}
219+
}
220+
221+
fn set_document_deletion_token_cost(&mut self, cost: Option<DocumentActionTokenCost>) {
222+
match self {
223+
DocumentType::V0(_) => { /* no-op */ }
224+
DocumentType::V1(v1) => v1.set_document_deletion_token_cost(cost),
225+
}
226+
}
227+
228+
fn set_document_transfer_token_cost(&mut self, cost: Option<DocumentActionTokenCost>) {
229+
match self {
230+
DocumentType::V0(_) => { /* no-op */ }
231+
DocumentType::V1(v1) => v1.set_document_transfer_token_cost(cost),
232+
}
233+
}
234+
235+
fn set_document_price_update_token_cost(&mut self, cost: Option<DocumentActionTokenCost>) {
236+
match self {
237+
DocumentType::V0(_) => { /* no-op */ }
238+
DocumentType::V1(v1) => v1.set_document_price_update_token_cost(cost),
239+
}
240+
}
241+
242+
fn set_document_purchase_token_cost(&mut self, cost: Option<DocumentActionTokenCost>) {
243+
match self {
244+
DocumentType::V0(_) => { /* no-op */ }
245+
DocumentType::V1(v1) => v1.set_document_purchase_token_cost(cost),
246+
}
247+
}
248+
}
249+
198250
impl DocumentTypeV0Getters for DocumentTypeRef<'_> {
199251
fn name(&self) -> &String {
200252
match self {
@@ -532,42 +584,42 @@ impl DocumentTypeV0Setters for DocumentTypeMutRef<'_> {
532584
}
533585

534586
impl DocumentTypeV1Getters for DocumentType {
535-
fn document_creation_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
587+
fn document_creation_token_cost(&self) -> Option<DocumentActionTokenCost> {
536588
match self {
537589
DocumentType::V0(_) => None,
538590
DocumentType::V1(v1) => v1.document_creation_token_cost(),
539591
}
540592
}
541593

542-
fn document_replacement_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
594+
fn document_replacement_token_cost(&self) -> Option<DocumentActionTokenCost> {
543595
match self {
544596
DocumentType::V0(_) => None,
545597
DocumentType::V1(v1) => v1.document_replacement_token_cost(),
546598
}
547599
}
548600

549-
fn document_deletion_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
601+
fn document_deletion_token_cost(&self) -> Option<DocumentActionTokenCost> {
550602
match self {
551603
DocumentType::V0(_) => None,
552604
DocumentType::V1(v1) => v1.document_deletion_token_cost(),
553605
}
554606
}
555607

556-
fn document_transfer_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
608+
fn document_transfer_token_cost(&self) -> Option<DocumentActionTokenCost> {
557609
match self {
558610
DocumentType::V0(_) => None,
559611
DocumentType::V1(v1) => v1.document_transfer_token_cost(),
560612
}
561613
}
562614

563-
fn document_update_price_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
615+
fn document_update_price_token_cost(&self) -> Option<DocumentActionTokenCost> {
564616
match self {
565617
DocumentType::V0(_) => None,
566618
DocumentType::V1(v1) => v1.document_update_price_token_cost(),
567619
}
568620
}
569621

570-
fn document_purchase_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
622+
fn document_purchase_token_cost(&self) -> Option<DocumentActionTokenCost> {
571623
match self {
572624
DocumentType::V0(_) => None,
573625
DocumentType::V1(v1) => v1.document_purchase_token_cost(),
@@ -576,42 +628,42 @@ impl DocumentTypeV1Getters for DocumentType {
576628
}
577629

578630
impl DocumentTypeV1Getters for DocumentTypeRef<'_> {
579-
fn document_creation_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
631+
fn document_creation_token_cost(&self) -> Option<DocumentActionTokenCost> {
580632
match self {
581633
DocumentTypeRef::V0(_) => None,
582634
DocumentTypeRef::V1(v1) => v1.document_creation_token_cost(),
583635
}
584636
}
585637

586-
fn document_replacement_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
638+
fn document_replacement_token_cost(&self) -> Option<DocumentActionTokenCost> {
587639
match self {
588640
DocumentTypeRef::V0(_) => None,
589641
DocumentTypeRef::V1(v1) => v1.document_replacement_token_cost(),
590642
}
591643
}
592644

593-
fn document_deletion_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
645+
fn document_deletion_token_cost(&self) -> Option<DocumentActionTokenCost> {
594646
match self {
595647
DocumentTypeRef::V0(_) => None,
596648
DocumentTypeRef::V1(v1) => v1.document_deletion_token_cost(),
597649
}
598650
}
599651

600-
fn document_transfer_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
652+
fn document_transfer_token_cost(&self) -> Option<DocumentActionTokenCost> {
601653
match self {
602654
DocumentTypeRef::V0(_) => None,
603655
DocumentTypeRef::V1(v1) => v1.document_transfer_token_cost(),
604656
}
605657
}
606658

607-
fn document_update_price_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
659+
fn document_update_price_token_cost(&self) -> Option<DocumentActionTokenCost> {
608660
match self {
609661
DocumentTypeRef::V0(_) => None,
610662
DocumentTypeRef::V1(v1) => v1.document_update_price_token_cost(),
611663
}
612664
}
613665

614-
fn document_purchase_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
666+
fn document_purchase_token_cost(&self) -> Option<DocumentActionTokenCost> {
615667
match self {
616668
DocumentTypeRef::V0(_) => None,
617669
DocumentTypeRef::V1(v1) => v1.document_purchase_token_cost(),
@@ -620,42 +672,42 @@ impl DocumentTypeV1Getters for DocumentTypeRef<'_> {
620672
}
621673

622674
impl DocumentTypeV1Getters for DocumentTypeMutRef<'_> {
623-
fn document_creation_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
675+
fn document_creation_token_cost(&self) -> Option<DocumentActionTokenCost> {
624676
match self {
625677
DocumentTypeMutRef::V0(_) => None,
626678
DocumentTypeMutRef::V1(v1) => v1.document_creation_token_cost(),
627679
}
628680
}
629681

630-
fn document_replacement_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
682+
fn document_replacement_token_cost(&self) -> Option<DocumentActionTokenCost> {
631683
match self {
632684
DocumentTypeMutRef::V0(_) => None,
633685
DocumentTypeMutRef::V1(v1) => v1.document_replacement_token_cost(),
634686
}
635687
}
636688

637-
fn document_deletion_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
689+
fn document_deletion_token_cost(&self) -> Option<DocumentActionTokenCost> {
638690
match self {
639691
DocumentTypeMutRef::V0(_) => None,
640692
DocumentTypeMutRef::V1(v1) => v1.document_deletion_token_cost(),
641693
}
642694
}
643695

644-
fn document_transfer_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
696+
fn document_transfer_token_cost(&self) -> Option<DocumentActionTokenCost> {
645697
match self {
646698
DocumentTypeMutRef::V0(_) => None,
647699
DocumentTypeMutRef::V1(v1) => v1.document_transfer_token_cost(),
648700
}
649701
}
650702

651-
fn document_update_price_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
703+
fn document_update_price_token_cost(&self) -> Option<DocumentActionTokenCost> {
652704
match self {
653705
DocumentTypeMutRef::V0(_) => None,
654706
DocumentTypeMutRef::V1(v1) => v1.document_update_price_token_cost(),
655707
}
656708
}
657709

658-
fn document_purchase_token_cost(&self) -> Option<(TokenContractPosition, TokenAmount)> {
710+
fn document_purchase_token_cost(&self) -> Option<DocumentActionTokenCost> {
659711
match self {
660712
DocumentTypeMutRef::V0(_) => None,
661713
DocumentTypeMutRef::V1(v1) => v1.document_purchase_token_cost(),

packages/rs-dpp/src/data_contract/document_type/accessors/v0/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ use crate::nft::TradeMode;
1414
use indexmap::IndexMap;
1515
use std::collections::{BTreeMap, BTreeSet};
1616

17+
pub trait DocumentTypeV0MutGetters {
18+
/// Gets the schema as mut
19+
fn schema_mut(&mut self) -> &mut Value;
20+
}
21+
1722
pub trait DocumentTypeV0Getters {
1823
/// Returns the name of the document type.
1924
fn name(&self) -> &String;

0 commit comments

Comments
 (0)