Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ impl EthConnectorContract {
_ => self.mint_eth_on_aurora(message_data.recipient, args.amount),
}
self.save_ft_contract();
sdk::return_output(0.to_string().as_bytes());
sdk::return_output("\"0\"".as_bytes());
}

/// Get accounts counter for statistics.
Expand Down
7 changes: 4 additions & 3 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::parameters::{
};

use crate::precompiles;
use crate::prelude::{Address, ToString, TryInto, Vec, H256, U256};
use crate::prelude::{Address, TryInto, Vec, H256, U256};
use crate::sdk;
use crate::state::AuroraStackState;
use crate::storage::{address_to_key, bytes_to_key, storage_to_key, KeyPrefix, KeyPrefixU8};
Expand Down Expand Up @@ -500,7 +500,7 @@ impl Engine {
/// IMPORTANT: This function should not panic, otherwise it won't
/// be possible to return the tokens to the sender.
pub fn receive_erc20_tokens(&mut self, args: &NEP141FtOnTransferArgs) {
let str_amount = args.amount.to_string();
let str_amount = crate::prelude::format!("\"{}\"", args.amount);
let output_on_fail = str_amount.as_bytes();

let token = sdk::predecessor_account_id();
Expand Down Expand Up @@ -576,8 +576,9 @@ impl Engine {
output_on_fail
);

// TODO(marX)
// Everything succeed so return "0"
sdk::return_output(b"0");
sdk::return_output(b"\"0\"");
}

pub fn nep141_erc20_map() -> BijectionMap<
Expand Down
10 changes: 4 additions & 6 deletions src/fungible_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use borsh::{BorshDeserialize, BorshSerialize};
use {
crate::connector,
crate::engine,
crate::json::parse_json,
crate::parameters::*,
crate::prelude::{self, Ordering, String, ToString, TryInto, Vec, U256},
crate::sdk,
Expand Down Expand Up @@ -245,12 +246,9 @@ impl FungibleToken {
let unused_amount = match sdk::promise_result(0) {
PromiseResult::NotReady => unreachable!(),
PromiseResult::Successful(value) => {
if let Ok(unused_amount) = String::from_utf8(value) {
let unused_amount = if let Ok(v) = unused_amount.parse::<u128>() {
v
} else {
amount
};
if let Some(unused_amount) =
parse_json(value.as_slice()).and_then(|x| (&x).try_into().ok())
{
if amount > unused_amount {
unused_amount
} else {
Expand Down
20 changes: 13 additions & 7 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ impl JsonValue {
#[allow(dead_code)]
pub fn u128(&self, key: &str) -> Result<u128, JsonError> {
match self {
JsonValue::Object(o) => match o.get(key).ok_or(JsonError::MissingValue)? {
JsonValue::String(n) => {
Ok(n.parse::<u128>().map_err(|_| JsonError::InvalidU128)?)
}
JsonValue::Number(_) => Err(JsonError::ExpectedStringGotNumber),
_ => Err(JsonError::InvalidU128),
},
JsonValue::Object(o) => o.get(key).ok_or(JsonError::MissingValue)?.try_into(),
_ => Err(JsonError::NotJsonType),
}
}
Expand Down Expand Up @@ -177,6 +171,18 @@ impl From<JsonObject> for JsonValue {
}
}

impl TryFrom<&JsonValue> for u128 {
type Error = JsonError;

fn try_from(value: &JsonValue) -> Result<Self, Self::Error> {
match value {
JsonValue::String(n) => Ok(n.parse::<u128>().map_err(|_| JsonError::InvalidU128)?),
JsonValue::Number(_) => Err(JsonError::ExpectedStringGotNumber),
_ => Err(JsonError::InvalidU128),
}
}
}

impl core::fmt::Debug for JsonValue {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match *self {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/erc20_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn test_ft_on_transfer() {

let res = runner.ft_on_transfer(nep141, alice.clone(), alice, amount, hex::encode(recipient));
// Transaction should succeed so return amount is 0
assert_eq!(res, "0");
assert_eq!(res, "\"0\"");

let balance = runner.balance_of(token, recipient, origin());
assert_eq!(balance, U256::from(amount));
Expand All @@ -290,7 +290,7 @@ fn test_ft_on_transfer_fail() {
let res = runner.ft_on_transfer(nep141, alice.clone(), alice, amount, hex::encode(recipient));

// Transaction should fail so it must return everything
assert_eq!(res, amount.to_string());
assert_eq!(res, format!("\"{}\"", amount.to_string()));
}

#[test]
Expand Down