From b0c6c49ce0756dbfdddc032deda29356522a3b0a Mon Sep 17 00:00:00 2001 From: laizy Date: Thu, 8 Dec 2022 15:25:25 +0800 Subject: [PATCH] update oom handler to new rustc nightly version (#119) --- examples/apitest/src/lib.rs | 2 +- examples/oep5token/src/lib.rs | 30 +++++++++++++-------------- examples/oep8token/src/lib.rs | 30 +++++++++++++-------------- examples/red-envlope/src/lib.rs | 6 +++--- examples/token-codegen/src/lib.rs | 12 +++++------ ontio-codegen/src/base58.rs | 2 +- ontio-codegen/src/contract.rs | 13 ++++++------ ontio-codegen/src/event.rs | 4 ++-- ontio-codegen/src/lib.rs | 2 +- ontio-std/src/abi/vm_value_builder.rs | 2 +- ontio-std/src/lib.rs | 7 ++++--- 11 files changed, 55 insertions(+), 55 deletions(-) diff --git a/examples/apitest/src/lib.rs b/examples/apitest/src/lib.rs index dc5ec5c..7f5b0e0 100644 --- a/examples/apitest/src/lib.rs +++ b/examples/apitest/src/lib.rs @@ -89,7 +89,7 @@ impl ApiTest for ApiTestInstance { fn call_wasm_name(&self, contract: &Address) -> String { let mut sink = Sink::new(16); sink.write("name".to_string()); - console::debug(&format!("{:?}", contract)); + console::debug(&format!("{contract:?}")); let res = runtime::call_contract(contract, sink.bytes()); let s = str::from_utf8(res.as_slice()).unwrap(); console::debug(s); diff --git a/examples/oep5token/src/lib.rs b/examples/oep5token/src/lib.rs index 3cc817b..deb88cb 100644 --- a/examples/oep5token/src/lib.rs +++ b/examples/oep5token/src/lib.rs @@ -52,25 +52,25 @@ impl Oep5Token for Oep5TokenInstance { database::get(KEY_TOTAL_SUPPLY).unwrap_or_default() } fn query_token_id_by_index(&self, idx: U128) -> String { - database::get(&utils::concat(PREFIX_INDEX, &idx)).unwrap_or_default() + database::get(utils::concat(PREFIX_INDEX, idx)).unwrap_or_default() } fn query_token_by_id(&self, token_id: String) -> String { let (_, _, image, _): (String, String, String, String) = - database::get(&utils::concat(PREFIX_TOKEN_ID, &token_id)).unwrap_or_default(); + database::get(utils::concat(PREFIX_TOKEN_ID, token_id)).unwrap_or_default(); image } fn balance_of(&self, address: &Address) -> U128 { - database::get(&utils::concat(PREFIX_BALANCE, address)).unwrap_or_default() + database::get(utils::concat(PREFIX_BALANCE, address)).unwrap_or_default() } fn owner_of(&self, token_id: String) -> Address { - database::get(&utils::concat(PREFIX_OWNER, &token_id)).unwrap_or_else(Address::zero) + database::get(utils::concat(PREFIX_OWNER, token_id)).unwrap_or_else(Address::zero) } fn transfer(&mut self, to: &Address, token_id: String) -> bool { let owner = self.owner_of(token_id.clone()); if !runtime::check_witness(&owner) { return false; } - database::put(&utils::concat(PREFIX_OWNER, &token_id), to); + database::put(utils::concat(PREFIX_OWNER, &token_id), to); true } fn transfer_multi(&mut self, states: &[(Address, String)]) -> bool { @@ -89,18 +89,18 @@ impl Oep5Token for Oep5TokenInstance { if !runtime::check_witness(&owner) { return false; } - database::put(&utils::concat(PREFIX_APPROVE, &token_id), to); + database::put(utils::concat(PREFIX_APPROVE, &token_id), to); true } fn get_approved(&mut self, token_id: String) -> Address { - database::get(&utils::concat(PREFIX_APPROVE, token_id)).unwrap_or_default() + database::get(utils::concat(PREFIX_APPROVE, token_id)).unwrap_or_default() } fn take_ownership(&mut self, token_id: String) -> bool { let to = self.get_approved(token_id.clone()); if !runtime::check_witness(&to) { return false; } - database::put(&utils::concat(PREFIX_OWNER, &token_id), to); + database::put(utils::concat(PREFIX_OWNER, &token_id), to); true } fn create_multi_tokens(&mut self, owner: &Address) -> bool { @@ -120,16 +120,16 @@ impl Oep5Token for Oep5TokenInstance { ) -> bool { let mut total_supply: U128 = database::get(KEY_TOTAL_SUPPLY).unwrap_or_default(); total_supply += 1; - database::put(KEY_TOTAL_SUPPLY, &total_supply); - let tmp = utils::concat(owner, &total_supply); - let token_id = runtime::sha256(&tmp).hex_string(); + database::put(KEY_TOTAL_SUPPLY, total_supply); + let tmp = utils::concat(owner, total_supply); + let token_id = runtime::sha256(tmp).hex_string(); let token = (token_id.clone(), name, url, token_type); - database::put(&utils::concat(PREFIX_INDEX, &total_supply), &token_id); - database::put(&utils::concat(PREFIX_OWNER, &token_id), owner); - database::put(&utils::concat(PREFIX_TOKEN_ID, &token_id), token); + database::put(utils::concat(PREFIX_INDEX, total_supply), &token_id); + database::put(utils::concat(PREFIX_OWNER, &token_id), owner); + database::put(utils::concat(PREFIX_TOKEN_ID, &token_id), token); let mut balance = self.balance_of(owner); balance += 1; - database::put(&utils::concat(PREFIX_BALANCE, owner), balance); + database::put(utils::concat(PREFIX_BALANCE, owner), balance); true } } diff --git a/examples/oep8token/src/lib.rs b/examples/oep8token/src/lib.rs index b5b0065..f0bfc6f 100644 --- a/examples/oep8token/src/lib.rs +++ b/examples/oep8token/src/lib.rs @@ -56,16 +56,16 @@ impl Oep8Token for Oep8TokenInstance { true } fn name(&self, token_id: String) -> String { - database::get(&utils::concat(token_id, NAME)).unwrap_or_default() + database::get(utils::concat(token_id, NAME)).unwrap_or_default() } fn symbol(&self, token_id: String) -> String { - database::get(&utils::concat(token_id, SYMBOL)).unwrap_or_default() + database::get(utils::concat(token_id, SYMBOL)).unwrap_or_default() } fn total_supply(&self, token_id: String) -> U128 { - database::get(&utils::concat(token_id, TOTAL_SUPPLY)).unwrap_or_default() + database::get(utils::concat(token_id, TOTAL_SUPPLY)).unwrap_or_default() } fn balance_of(&self, address: &Address, token_id: String) -> U128 { - database::get(&utils::concat(token_id, (BALANCE, address))).unwrap_or_default() + database::get(utils::concat(token_id, (BALANCE, address))).unwrap_or_default() } fn transfer(&mut self, from: &Address, to: &Address, amount: U128, token_id: String) -> bool { assert!(self.check_token_id(token_id.clone())); @@ -83,7 +83,7 @@ impl Oep8Token for Oep8TokenInstance { } let to_key = utils::concat(&balance_key, to); let to_balance: U128 = database::get(&to_key).unwrap_or_default(); - database::put(&to_key, amount + to_balance); + database::put(to_key, amount + to_balance); self.Transfer(from, to, amount, token_id); true } @@ -110,13 +110,13 @@ impl Oep8Token for Oep8TokenInstance { assert!(owner_balance >= amount); assert!(amount.raw() > 0); let approve_key = utils::concat(token_id.clone(), (APPROVE, owner, spender)); - database::put(&approve_key, amount); + database::put(approve_key, amount); self.Approve(owner, spender, amount, token_id); true } fn allowance(&mut self, owner: &Address, spender: &Address, token_id: String) -> U128 { let approve_key = utils::concat(token_id, (APPROVE, owner, spender)); - database::get(&approve_key).unwrap_or_default() + database::get(approve_key).unwrap_or_default() } fn transfer_from( &mut self, spender: &Address, from: &Address, to: &Address, amount: U128, token_id: String, @@ -126,11 +126,11 @@ impl Oep8Token for Oep8TokenInstance { let approval = self.allowance(from, spender, token_id.clone()); assert!(amount <= approval); let fromval = self.balance_of(from, token_id.clone()); - database::put(&utils::concat(token_id.clone(), (BALANCE, from)), fromval - amount); + database::put(utils::concat(token_id.clone(), (BALANCE, from)), fromval - amount); let toval = self.balance_of(to, token_id.clone()); - database::put(&utils::concat(token_id.clone(), (BALANCE, to)), toval + amount); + database::put(utils::concat(token_id.clone(), (BALANCE, to)), toval + amount); let approve_key = utils::concat(token_id, (APPROVE, from, spender)); - database::put(&approve_key, approval - amount); + database::put(approve_key, approval - amount); true } fn approve_multi(&mut self, obj: &[(Address, Address, U128, String)]) -> bool { @@ -178,16 +178,16 @@ impl Oep8Token for Oep8TokenInstance { let token_symbol = token_symbol_list[index]; let token_total_supply = U128::new(token_supply_list[index]); let token_id = format!("{}", index + 1); - database::put(&utils::concat(token_id.clone(), NAME), token_name); - database::put(&utils::concat(token_id.clone(), SYMBOL), token_symbol); - database::put(&utils::concat(token_id.clone(), TOTAL_SUPPLY), token_total_supply); - database::put(&utils::concat(token_id.clone(), (BALANCE, ADMIN)), token_total_supply); + database::put(utils::concat(token_id.clone(), NAME), token_name); + database::put(utils::concat(token_id.clone(), SYMBOL), token_symbol); + database::put(utils::concat(token_id.clone(), TOTAL_SUPPLY), token_total_supply); + database::put(utils::concat(token_id.clone(), (BALANCE, ADMIN)), token_total_supply); self.Transfer(&ADMIN, &ADMIN, token_total_supply, token_id); } true } fn check_token_id(&self, token_id: String) -> bool { - database::get::<_, String>(&utils::concat(token_id, NAME)).is_some() + database::get::<_, String>(utils::concat(token_id, NAME)).is_some() } } diff --git a/examples/red-envlope/src/lib.rs b/examples/red-envlope/src/lib.rs index e56fba6..fce676c 100644 --- a/examples/red-envlope/src/lib.rs +++ b/examples/red-envlope/src/lib.rs @@ -43,8 +43,8 @@ fn create_red_envlope(owner: Address, pack_count: U128, amount: U128, token_addr let key = [SENT_PREFIX.as_bytes(), owner.as_ref()].concat(); let mut sent_count = database::get(&key).unwrap_or(0u64); sent_count += 1; - database::put(&key, sent_count); - let hash_key = [owner.as_ref(), format!("{}", sent_count).as_bytes()].concat(); + database::put(key, sent_count); + let hash_key = [owner.as_ref(), format!("{sent_count}").as_bytes()].concat(); let hash = format!("{:?}", runtime::sha256(hash_key)); let hash_bytes = hash.as_bytes(); let re_key = [RE_PREFIX.as_bytes(), hash_bytes].concat(); @@ -75,7 +75,7 @@ fn create_red_envlope(owner: Address, pack_count: U128, amount: U128, token_addr remain_package_count: pack_count, records: Vec::new(), }; - database::put(&re_key, es); + database::put(re_key, es); create_red_envlope_event(owner.as_ref(), pack_count, amount, token_addr.as_ref()); true } diff --git a/examples/token-codegen/src/lib.rs b/examples/token-codegen/src/lib.rs index fa95a1c..9d62b95 100644 --- a/examples/token-codegen/src/lib.rs +++ b/examples/token-codegen/src/lib.rs @@ -41,7 +41,7 @@ impl MyToken for MyTokenInstance { return false; } database::put(KEY_TOTAL_SUPPLY, TOTAL_SUPPLY); - database::put(&utils::gen_balance_key(owner), TOTAL_SUPPLY); + database::put(utils::gen_balance_key(owner), TOTAL_SUPPLY); true } @@ -50,7 +50,7 @@ impl MyToken for MyTokenInstance { } fn balance_of(&self, owner: &Address) -> U128 { - database::get(&utils::gen_balance_key(owner)).unwrap_or_default() + database::get(utils::gen_balance_key(owner)).unwrap_or_default() } fn transfer(&mut self, from: &Address, to: &Address, amount: U128) -> bool { @@ -64,8 +64,8 @@ impl MyToken for MyTokenInstance { } else { frmbal -= amount; tobal += amount; - database::put(&utils::gen_balance_key(from), &frmbal); - database::put(&utils::gen_balance_key(to), &tobal); + database::put(utils::gen_balance_key(from), frmbal); + database::put(utils::gen_balance_key(to), tobal); self.Transfer(from, to, amount); true } @@ -90,7 +90,7 @@ impl MyToken for MyTokenInstance { if apprbal < amount { false } else { - database::put(&utils::gen_approve_key(approves, receiver), amount); + database::put(utils::gen_approve_key(approves, receiver), amount); self.Approve(approves, receiver, amount); true } @@ -117,7 +117,7 @@ impl MyToken for MyTokenInstance { true } fn allowance(&mut self, approves: &Address, receiver: &Address) -> U128 { - database::get(&utils::gen_approve_key(approves, receiver)).unwrap_or_default() + database::get(utils::gen_approve_key(approves, receiver)).unwrap_or_default() } fn total_supply(&self) -> U128 { diff --git a/ontio-codegen/src/base58.rs b/ontio-codegen/src/base58.rs index 1e2bcf5..305d5eb 100644 --- a/ontio-codegen/src/base58.rs +++ b/ontio-codegen/src/base58.rs @@ -46,7 +46,7 @@ pub fn decode_base58(val: &str) -> Result<[u8; 20], String> { let mut bigint: BigUint = Zero::zero(); for c in new_val.chars() { match CHARS.find(c) { - None => return Err(format!("invalid char: {}", c)), + None => return Err(format!("invalid char: {c}")), Some(x) => { bigint = bigint * &b58 + x.to_biguint().unwrap(); } diff --git a/ontio-codegen/src/contract.rs b/ontio-codegen/src/contract.rs index d9d1340..249da56 100644 --- a/ontio-codegen/src/contract.rs +++ b/ontio-codegen/src/contract.rs @@ -133,7 +133,7 @@ fn generate_dispatcher(contract: &Contract) -> proc_macro2::TokenStream { ContractField::Action(ref action) => { let action_name = &action.name; let action_literal = syn::LitStr::new(&action_name.to_string(), proc_macro2::Span::call_site()); - let args = action.params.iter().map(|&(_, ref ty)| { + let args = action.params.iter().map(|(_, ty)| { let ty :&syn::Type = ty; match ty { syn::Type::Reference(refer) => { @@ -189,8 +189,7 @@ fn generate_dispatcher(contract: &Contract) -> proc_macro2::TokenStream { let contract_name = &contract.name; - let dispatcher_name = - syn::Ident::new(&format!("{}Dispatcher", contract_name), Span::call_site()); + let dispatcher_name = syn::Ident::new(&format!("{contract_name}Dispatcher"), Span::call_site()); quote! { pub struct #dispatcher_name { @@ -230,8 +229,8 @@ fn generate_event(contract: &Contract) -> proc_macro2::TokenStream { ContractField::Event(ref event) => { let event_sig = &event.method_sig; let event_body = { - let args_type = event.params.iter().map(|&(_, ref ty)| quote! { #ty }); - let args_name = event.params.iter().map(|&(ref pat, _)| quote! { #pat }); + let args_type = event.params.iter().map(|(_, ty)| quote! { #ty }); + let args_name = event.params.iter().map(|(pat, _)| quote! { #pat }); quote! { { let mut sink = ontio_std::abi::Sink::new(16); #(sink.write::<#args_type>(#args_name);)* @@ -244,11 +243,11 @@ fn generate_event(contract: &Contract) -> proc_macro2::TokenStream { #event_body } } - &ContractField::Action(ref action) => { + ContractField::Action(action) => { let method = &action.method; quote! { #method } } - &ContractField::Unhandle(ref item) => quote! { #item }, + ContractField::Unhandle(item) => quote! { #item }, }) .collect(); diff --git a/ontio-codegen/src/event.rs b/ontio-codegen/src/event.rs index c10a9ca..b0d33df 100644 --- a/ontio-codegen/src/event.rs +++ b/ontio-codegen/src/event.rs @@ -24,9 +24,9 @@ pub fn quote(method_name: String, func: &syn::ItemFn) -> proc_macro2::TokenStrea let mut es = ontio_std::abi::EventBuilder::new(); es = es.string(#method_name); }; - let body = params.iter().map(|&(ref pat, ref ty)| { + let body = params.iter().map(|(pat, ty)| { let mut param_type = ty.into_token_stream().to_string(); - param_type = param_type.replace(" ", ""); + param_type = param_type.replace(' ', ""); match param_type.as_str() { "Address" | "&Address" => quote! {es = es.address(#pat)}, "U128" => quote! {es = es.number(#pat)}, diff --git a/ontio-codegen/src/lib.rs b/ontio-codegen/src/lib.rs index 429d448..b0657bf 100644 --- a/ontio-codegen/src/lib.rs +++ b/ontio-codegen/src/lib.rs @@ -32,7 +32,7 @@ pub fn event(metadata: TokenStream, input: TokenStream) -> TokenStream { } else { method_name = metadata.to_string(); method_name = method_name.replace("name", ""); - method_name = method_name.replace("=", ""); + method_name = method_name.replace('=', ""); } method_name = method_name.to_mixed_case(); let stream = event::quote(method_name, func); diff --git a/ontio-std/src/abi/vm_value_builder.rs b/ontio-std/src/abi/vm_value_builder.rs index 60d76c8..3494c2c 100644 --- a/ontio-std/src/abi/vm_value_builder.rs +++ b/ontio-std/src/abi/vm_value_builder.rs @@ -23,7 +23,7 @@ pub struct NestedVmValueBuilder<'a> { current: VmValueBuilderCommon, } -impl<'a> NestedVmValueBuilder<'_> { +impl NestedVmValueBuilder<'_> { pub fn finish(self) { let mut buf = self.current.sink.into(); buf[1..5].copy_from_slice(&self.current.num_entry.to_le_bytes()); diff --git a/ontio-std/src/lib.rs b/ontio-std/src/lib.rs index 0eb567b..500b693 100644 --- a/ontio-std/src/lib.rs +++ b/ontio-std/src/lib.rs @@ -6,6 +6,7 @@ #![feature(exclusive_range_pattern)] #![feature(proc_macro_hygiene)] #![feature(panic_info_message)] +#![feature(alloc_error_handler)] //#![feature(trace_macros)] @@ -29,7 +30,7 @@ cfg_if::cfg_if! { #[no_mangle] #[panic_handler] pub fn panic_fmt(info: &core::panic::PanicInfo) -> ! { - let msg = info.message().map(|msg| format!("{}", msg)).unwrap_or_default(); + let msg = info.message().map(|msg| format!("{msg}")).unwrap_or_default(); let (file, line) = if let Some(loc) = info.location() { (loc.file(), loc.line()) } else { @@ -37,7 +38,7 @@ cfg_if::cfg_if! { }; - let panic_msg = format!("{} at {}:{}", msg, file, line); + let panic_msg = format!("{msg} at {file}:{line}"); runtime::panic(&panic_msg) } @@ -45,7 +46,7 @@ cfg_if::cfg_if! { extern "C" fn eh_personality() {} /// Overrides the default oom - #[lang = "oom"] + #[alloc_error_handler] #[no_mangle] pub fn oom(_: core::alloc::Layout) -> ! { core::intrinsics::abort()