Skip to content

Commit

Permalink
update oom handler to new rustc nightly version (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
laizy authored Dec 8, 2022
1 parent bb8d531 commit b0c6c49
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion examples/apitest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions examples/oep5token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
}
Expand Down
30 changes: 15 additions & 15 deletions examples/oep8token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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
}
Expand All @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
}
}

Expand Down
6 changes: 3 additions & 3 deletions examples/red-envlope/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions examples/token-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ontio-codegen/src/base58.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
13 changes: 6 additions & 7 deletions ontio-codegen/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<T:#contract_name> {
Expand Down Expand Up @@ -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);)*
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions ontio-codegen/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
2 changes: 1 addition & 1 deletion ontio-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ontio-std/src/abi/vm_value_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 4 additions & 3 deletions ontio-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![feature(exclusive_range_pattern)]
#![feature(proc_macro_hygiene)]
#![feature(panic_info_message)]
#![feature(alloc_error_handler)]

//#![feature(trace_macros)]

Expand All @@ -29,23 +30,23 @@ 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 {
("", 0)
};


let panic_msg = format!("{} at {}:{}", msg, file, line);
let panic_msg = format!("{msg} at {file}:{line}");
runtime::panic(&panic_msg)
}

#[lang = "eh_personality"]
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()
Expand Down

0 comments on commit b0c6c49

Please sign in to comment.