Skip to content

Commit a800a55

Browse files
RickyLBmehcode
andauthored
feat: TokenReject
Co-authored-by: Ryan Leckey <[email protected]>
1 parent 337818c commit a800a55

File tree

22 files changed

+2317
-456
lines changed

22 files changed

+2317
-456
lines changed

Cargo.lock

Lines changed: 413 additions & 442 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobufs/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ version = "0.11.0"
2525
[build-dependencies]
2626
anyhow = "1.0.55"
2727
tonic-build = "0.11.0"
28+
regex = "1.10.6"
29+
fs_extra = "1.3.0"

protobufs/build.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use std::fs::{
2626
};
2727
use std::path::Path;
2828

29+
use regex::RegexBuilder;
30+
2931
const DERIVE_EQ_HASH: &str = "#[derive(Eq, Hash)]";
3032
const DERIVE_EQ_HASH_COPY: &str = "#[derive(Copy, Eq, Hash)]";
3133
const SERVICES_FOLDER: &str = "./protobufs/services";
@@ -40,14 +42,45 @@ fn main() -> anyhow::Result<()> {
4042
anyhow::bail!("Folder {SERVICES_FOLDER} does not exist; do you need to `git submodule update --init`?");
4143
}
4244

43-
let services: Vec<_> = read_dir(services_path)?
45+
let out_dir = env::var("OUT_DIR")?;
46+
let out_path = Path::new(&out_dir);
47+
let services_tmp_path = out_path.join("services_src");
48+
49+
// ensure we start fresh
50+
let _ = fs::remove_dir_all(&services_tmp_path);
51+
52+
create_dir_all(&services_tmp_path)?;
53+
54+
// copy over services into our tmp path so we can edit
55+
fs_extra::copy_items(
56+
&[services_path],
57+
&out_path,
58+
&fs_extra::dir::CopyOptions::new().overwrite(true).copy_inside(false),
59+
)?;
60+
fs::rename(out_path.join("services"), &services_tmp_path)?;
61+
62+
let services: Vec<_> = read_dir(&services_tmp_path)?
4463
.filter_map(|entry| {
4564
let entry = entry.ok()?;
4665
entry.file_type().ok()?.is_file().then(|| entry.path())
4766
})
4867
.collect();
4968

50-
let mut cfg = tonic_build::configure().build_server(cfg!(feature = "server"));
69+
// iterate through each file
70+
let re_package = RegexBuilder::new(r"^package (.*);$").multi_line(true).build()?;
71+
for service in &services {
72+
let contents = fs::read_to_string(service)?;
73+
74+
// ensure that every `package _` entry is `package proto;`
75+
let contents = re_package.replace(&contents, "package proto;");
76+
77+
// remove com.hedera.hapi.node.addressbook. prefix
78+
let contents = contents.replace("com.hedera.hapi.node.addressbook.", "");
79+
80+
fs::write(service, &*contents)?;
81+
}
82+
83+
let mut cfg = tonic_build::configure();
5184

5285
// most of the protobufs in "basic types" should be Eq + Hash + Copy
5386
// any protobufs that would typically be used as parameter, that meet the requirements of those
@@ -98,7 +131,7 @@ fn main() -> anyhow::Result<()> {
98131
"]"#,
99132
);
100133

101-
cfg.compile(&services, &["./protobufs/services/"])?;
134+
cfg.compile(&services, &[services_tmp_path])?;
102135

103136
// NOTE: prost generates rust doc comments and fails to remove the leading * line
104137
remove_useless_comments(&Path::new(&env::var("OUT_DIR")?).join("proto.rs"))?;

src/account/account_balance.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ pub struct AccountBalance {
4242
pub hbars: Hbar,
4343

4444
/// Token balances for the referenced account.
45-
#[deprecated = "use a mirror query"]
46-
#[allow(deprecated)]
45+
// #[deprecated = "use a mirror query"]
4746
pub tokens: HashMap<TokenId, u64>,
4847

4948
/// Token decimals for the referenced account.

src/fee_schedules.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,18 @@ pub enum RequestType {
409409

410410
/// Update the metadata of one or more NFT's of a specific token type.
411411
TokenUpdateNfts,
412+
413+
/// Create a new node.
414+
NodeCreate,
415+
416+
/// Update an existing node.
417+
NodeUpdate,
418+
419+
/// Delete a node.
420+
NodeDelete,
421+
422+
/// Reject tokens.
423+
TokenReject,
412424
}
413425

414426
impl FromProtobuf<services::HederaFunctionality> for RequestType {
@@ -490,6 +502,10 @@ impl FromProtobuf<services::HederaFunctionality> for RequestType {
490502
HederaFunctionality::UtilPrng => Self::UtilPrng,
491503
HederaFunctionality::TransactionGetFastRecord => Self::TransactionGetFastRecord,
492504
HederaFunctionality::TokenUpdateNfts => Self::TokenUpdateNfts,
505+
HederaFunctionality::NodeCreate => Self::NodeCreate,
506+
HederaFunctionality::NodeUpdate => Self::NodeUpdate,
507+
HederaFunctionality::NodeDelete => Self::NodeDelete,
508+
HederaFunctionality::TokenReject => Self::TokenReject,
493509
};
494510

495511
Ok(value)
@@ -577,6 +593,10 @@ impl ToProtobuf for RequestType {
577593
Self::UtilPrng => HederaFunctionality::UtilPrng,
578594
Self::TransactionGetFastRecord => HederaFunctionality::TransactionGetFastRecord,
579595
Self::TokenUpdateNfts => HederaFunctionality::TokenUpdateNfts,
596+
Self::NodeCreate => HederaFunctionality::NodeCreate,
597+
Self::NodeUpdate => HederaFunctionality::NodeUpdate,
598+
Self::NodeDelete => HederaFunctionality::NodeDelete,
599+
Self::TokenReject => HederaFunctionality::TokenReject,
580600
}
581601
}
582602
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ pub use token::{
326326
TokenNftInfoQuery,
327327
TokenNftTransfer,
328328
TokenPauseTransaction,
329+
TokenRejectFlow,
330+
TokenRejectTransaction,
329331
TokenRevokeKycTransaction,
330332
TokenSupplyType,
331333
TokenType,

src/node_address.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl ToProtobuf for NodeAddress {
114114
.map(|it| services::ServiceEndpoint {
115115
ip_address_v4: it.ip().octets().to_vec(),
116116
port: i32::from(it.port()),
117+
domain_name: "".to_owned(),
117118
})
118119
.collect();
119120

src/schedule/schedulable_transaction_body.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mod data {
4646
TokenGrantKycTransactionData as TokenGrantKyc,
4747
TokenMintTransactionData as TokenMint,
4848
TokenPauseTransactionData as TokenPause,
49+
TokenRejectTransactionData as TokenReject,
4950
TokenRevokeKycTransactionData as TokenRevokeKyc,
5051
TokenUnfreezeTransactionData as TokenUnfreeze,
5152
TokenUnpauseTransactionData as TokenUnpause,
@@ -133,11 +134,12 @@ pub(super) enum AnySchedulableTransactionData {
133134
TokenUnpause(data::TokenUnpause),
134135
TokenUpdate(data::TokenUpdate),
135136
TokenWipe(data::TokenWipe),
137+
TokenUpdateNfts(data::TokenUpdateNfts),
138+
TokenReject(data::TokenReject),
136139
SystemDelete(data::SystemDelete),
137140
SystemUndelete(data::SystemUndelete),
138141
Freeze(data::Freeze),
139142
ScheduleDelete(data::ScheduleDelete),
140-
TokenUpdateNfts(data::TokenUpdateNfts),
141143
}
142144

143145
impl AnySchedulableTransactionData {
@@ -185,6 +187,7 @@ impl AnySchedulableTransactionData {
185187
AnySchedulableTransactionData::TokenUnpause(it) => it.default_max_transaction_fee(),
186188
AnySchedulableTransactionData::TokenUpdate(it) => it.default_max_transaction_fee(),
187189
AnySchedulableTransactionData::TokenWipe(it) => it.default_max_transaction_fee(),
190+
AnySchedulableTransactionData::TokenReject(it) => it.default_max_transaction_fee(),
188191
AnySchedulableTransactionData::SystemDelete(it) => it.default_max_transaction_fee(),
189192
AnySchedulableTransactionData::SystemUndelete(it) => it.default_max_transaction_fee(),
190193
AnySchedulableTransactionData::Freeze(it) => it.default_max_transaction_fee(),
@@ -280,13 +283,17 @@ impl FromProtobuf<services::schedulable_transaction_body::Data> for AnySchedulab
280283
Data::TokenUnpause(it) => {
281284
Ok(Self::TokenUnpause(data::TokenUnpause::from_protobuf(it)?))
282285
}
286+
Data::TokenReject(it) => Ok(Self::TokenReject(data::TokenReject::from_protobuf(it)?)),
283287
Data::ScheduleDelete(it) => {
284288
Ok(Self::ScheduleDelete(data::ScheduleDelete::from_protobuf(it)?))
285289
}
286290
Data::UtilPrng(it) => Ok(Self::Prng(data::Prng::from_protobuf(it)?)),
287291
Data::TokenUpdateNfts(it) => {
288292
Ok(Self::TokenUpdateNfts(data::TokenUpdateNfts::from_protobuf(it)?))
289293
}
294+
Data::NodeCreate(_) => todo!(),
295+
Data::NodeUpdate(_) => todo!(),
296+
Data::NodeDelete(_) => todo!(),
290297
}
291298
}
292299
}
@@ -414,6 +421,9 @@ impl ToSchedulableTransactionDataProtobuf for AnySchedulableTransactionData {
414421
AnySchedulableTransactionData::TokenUpdateNfts(it) => {
415422
it.to_schedulable_transaction_data_protobuf()
416423
}
424+
AnySchedulableTransactionData::TokenReject(it) => {
425+
it.to_schedulable_transaction_data_protobuf()
426+
}
417427
}
418428
}
419429
}
@@ -458,6 +468,7 @@ impl TryFrom<AnyTransactionData> for AnySchedulableTransactionData {
458468
AnyTransactionData::TokenUnpause(it) => Ok(Self::TokenUnpause(it)),
459469
AnyTransactionData::TokenUpdate(it) => Ok(Self::TokenUpdate(it)),
460470
AnyTransactionData::TokenWipe(it) => Ok(Self::TokenWipe(it)),
471+
AnyTransactionData::TokenReject(it) => Ok(Self::TokenReject(it)),
461472
AnyTransactionData::SystemDelete(it) => Ok(Self::SystemDelete(it)),
462473
AnyTransactionData::SystemUndelete(it) => Ok(Self::SystemUndelete(it)),
463474
AnyTransactionData::Freeze(it) => Ok(Self::Freeze(it)),
@@ -527,6 +538,7 @@ impl From<AnySchedulableTransactionData> for AnyTransactionData {
527538
AnySchedulableTransactionData::ScheduleDelete(it) => Self::ScheduleDelete(it),
528539
AnySchedulableTransactionData::Prng(it) => Self::Prng(it),
529540
AnySchedulableTransactionData::TokenUpdateNfts(it) => Self::TokenUpdateNfts(it),
541+
AnySchedulableTransactionData::TokenReject(it) => Self::TokenReject(it),
530542
}
531543
}
532544
}

src/snapshots/transaction_record/serialize.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ TransactionRecord {
103103
2,
104104
3,
105105
],
106+
node_id: 1,
106107
},
107108
),
108109
transaction_hash: [

0 commit comments

Comments
 (0)