Skip to content

Commit

Permalink
Use the SDK conversion from address to identifier. (stellar#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmkozh authored Oct 11, 2022
1 parent fb0634e commit 72101a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ codegen-units = 1
lto = true

[patch.crates-io]
soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "3992556b" }
soroban-spec = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "3992556b" }
soroban-auth = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "3992556b" }
soroban-sdk-macros = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "3992556b" }
soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "38f3768" }
soroban-spec = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "38f3768" }
soroban-auth = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "38f3768" }
soroban-sdk-macros = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "38f3768" }
soroban-env-common = { git = "https://github.com/stellar/rs-soroban-env", rev = "91cf595" }
soroban-env-guest = { git = "https://github.com/stellar/rs-soroban-env", rev = "91cf595" }
soroban-env-host = { git = "https://github.com/stellar/rs-soroban-env", rev = "91cf595" }
Expand Down
14 changes: 3 additions & 11 deletions timelock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#[cfg(feature = "testutils")]
extern crate std;

use soroban_sdk::{contractimpl, contracttype, Address, BigInt, BytesN, Env, Vec};
use soroban_sdk::{contractimpl, contracttype, BigInt, BytesN, Env, Vec};

mod token {
soroban_sdk::contractimport!(file = "../soroban_token_spec.wasm");
Expand Down Expand Up @@ -83,9 +83,8 @@ impl ClaimableBalanceContract {
panic!("contract has been already initialized");
}

let from_id = address_to_id(env.invoker());
// Transfer token to this contract address.
transfer_from_account_to_contract(&env, &token, &from_id, &amount);
transfer_from_account_to_contract(&env, &token, &env.invoker().into(), &amount);
// Store all the necessary info to allow one of the claimants to claim it.
env.data().set(
DataKey::Balance,
Expand All @@ -110,7 +109,7 @@ impl ClaimableBalanceContract {
panic!("time predicate is not fulfilled");
}

let claimant_id = address_to_id(env.invoker());
let claimant_id = env.invoker().into();
let claimants = &claimable_balance.claimants;
if !claimants.contains(&claimant_id) {
panic!("claimant is not allowed to claim this balance");
Expand All @@ -137,13 +136,6 @@ fn get_contract_id(e: &Env) -> Identifier {
Identifier::Contract(e.get_current_contract().into())
}

fn address_to_id(address: Address) -> Identifier {
match address {
Address::Account(a) => Identifier::Account(a),
Address::Contract(c) => Identifier::Contract(c),
}
}

fn transfer_from_account_to_contract(
e: &Env,
token_id: &BytesN<32>,
Expand Down

0 comments on commit 72101a2

Please sign in to comment.