Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewAddress -> Address #791

Merged
merged 2 commits into from
Feb 3, 2025
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 crates/jstz_cli/src/bridge/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use jstz_proto::context::new_account::Addressable;
use jstz_proto::context::account::Addressable;
use log::{debug, info};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion crates/jstz_cli/src/bridge/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
term::styles,
utils::AddressOrAlias,
};
use jstz_proto::context::new_account::Addressable;
use jstz_proto::context::account::Addressable;
use log::debug;

pub async fn exec(
Expand Down
12 changes: 6 additions & 6 deletions crates/jstz_cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use jstz_crypto::{
public_key::PublicKey, public_key_hash::PublicKeyHash, secret_key::SecretKey,
smart_function_hash::SmartFunctionHash,
};
use jstz_proto::context::new_account::NewAddress;
use jstz_proto::context::account::Address;
use log::debug;
use octez::{OctezClient, OctezNode, OctezRollupNode};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -50,7 +50,7 @@ pub enum Account {
}

impl Account {
pub fn address(&self) -> NewAddress {
pub fn address(&self) -> Address {
match self {
Account::User(user) => user.address.clone().into(),
Account::SmartFunction(sf) => sf.address.clone().into(),
Expand Down Expand Up @@ -149,7 +149,7 @@ impl AccountConfig {
}

impl AddressOrAlias {
pub fn resolve(&self, cfg: &Config) -> Result<NewAddress> {
pub fn resolve(&self, cfg: &Config) -> Result<Address> {
match self {
AddressOrAlias::Address(address) => Ok(address.clone()),
AddressOrAlias::Alias(alias) => {
Expand All @@ -166,7 +166,7 @@ impl AddressOrAlias {
pub fn resolve_or_use_current_user(
account: Option<AddressOrAlias>,
cfg: &Config,
) -> Result<NewAddress> {
) -> Result<Address> {
match account {
Some(account) => account.resolve(cfg),
None => cfg
Expand All @@ -183,7 +183,7 @@ impl AddressOrAlias {
&self,
cfg: &Config,
network: &Option<NetworkName>,
) -> Result<NewAddress> {
) -> Result<Address> {
match self {
AddressOrAlias::Address(address) => Ok(address.clone()),
AddressOrAlias::Alias(alias) => {
Expand All @@ -196,7 +196,7 @@ impl AddressOrAlias {
alias
))?;

let address = NewAddress::from_base58(&alias_info.address)
let address = Address::from_base58(&alias_info.address)
.map_err(|e| user_error!("{}", e))?;

Ok(address)
Expand Down
2 changes: 1 addition & 1 deletion crates/jstz_cli/src/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use boa_engine::JsError;
use jstz_proto::{
context::new_account::ParsedCode,
context::account::ParsedCode,
operation::{Content, DeployFunction, Operation, SignedOperation},
receipt::{ReceiptContent, ReceiptResult},
};
Expand Down
12 changes: 6 additions & 6 deletions crates/jstz_cli/src/jstz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{bail, Result};
use jstz_crypto::smart_function_hash::SmartFunctionHash;
use jstz_proto::{
api::KvValue,
context::new_account::{Addressable, NewAddress, Nonce},
context::account::{Address, Addressable, Nonce},
operation::{OperationHash, SignedOperation},
receipt::Receipt,
};
Expand All @@ -28,7 +28,7 @@ impl JstzClient {
}
}

pub fn logs_stream(&self, address: &NewAddress) -> EventSource {
pub fn logs_stream(&self, address: &Address) -> EventSource {
let url = format!("{}/logs/{}/stream", self.endpoint, address);
EventSource::get(url)
}
Expand All @@ -50,7 +50,7 @@ impl JstzClient {
}
}

pub async fn get_nonce(&self, address: &NewAddress) -> Result<Nonce> {
pub async fn get_nonce(&self, address: &Address) -> Result<Nonce> {
let response = self
.get(&format!("{}/accounts/{}/nonce", self.endpoint, address))
.await?;
Expand Down Expand Up @@ -86,7 +86,7 @@ impl JstzClient {
}
}

pub async fn get_balance(&self, address: &NewAddress) -> Result<u64> {
pub async fn get_balance(&self, address: &Address) -> Result<u64> {
let response = self
.get(&format!("{}/accounts/{}/balance", self.endpoint, address))
.await?;
Expand All @@ -105,7 +105,7 @@ impl JstzClient {

pub async fn get_value(
&self,
address: &NewAddress,
address: &Address,
key: &str,
) -> Result<Option<KvValue>> {
let response = self
Expand All @@ -128,7 +128,7 @@ impl JstzClient {

pub async fn get_subkey_list(
&self,
address: &NewAddress,
address: &Address,
key: &Option<String>,
) -> Result<Option<Vec<String>>> {
let url = match key {
Expand Down
12 changes: 6 additions & 6 deletions crates/jstz_cli/src/repl/debug_api/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use boa_engine::{
};
use jstz_core::runtime;
use jstz_crypto::{hash::Hash, smart_function_hash::SmartFunctionHash};
use jstz_proto::context::new_account::{Account, NewAddress};
use jstz_proto::context::account::{Account, Address};

fn try_parse_address(account: &str) -> JsResult<NewAddress> {
NewAddress::from_base58(account).map_err(|_| {
fn try_parse_address(account: &str) -> JsResult<Address> {
Address::from_base58(account).map_err(|_| {
JsNativeError::typ()
.with_message("Could not parse the address.")
.into()
Expand Down Expand Up @@ -124,7 +124,7 @@ impl AccountApi {

#[cfg(test)]
mod tests {
use jstz_proto::context::new_account::Addressable;
use jstz_proto::context::account::Addressable;

use super::*;

Expand All @@ -135,12 +135,12 @@ mod tests {
fn test_try_parse_address() {
// Test valid tz1 address
let result = try_parse_address(TEST_TZ1).unwrap();
assert!(matches!(result, NewAddress::User(_)));
assert!(matches!(result, Address::User(_)));
assert_eq!(result.to_base58(), TEST_TZ1);

// Test valid KT1 address
let result = try_parse_address(TEST_KT1).unwrap();
assert!(matches!(result, NewAddress::SmartFunction(_)));
assert!(matches!(result, Address::SmartFunction(_)));
assert_eq!(result.to_base58(), TEST_KT1);
}

Expand Down
6 changes: 3 additions & 3 deletions crates/jstz_cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use anyhow::bail;
use http::{HeaderMap, Method, Uri};
use jstz_proto::context::new_account::{Addressable, NewAddress};
use jstz_proto::context::account::{Address, Addressable};
use jstz_proto::executor::JSTZ_HOST;
use jstz_proto::{
operation::{Content as OperationContent, Operation, RunFunction, SignedOperation},
Expand Down Expand Up @@ -100,7 +100,7 @@ pub async fn exec(

// 3. Construct the signed operation
let nonce = jstz_client
.get_nonce(&NewAddress::User(user.address.clone()))
.get_nonce(&Address::User(user.address.clone()))
.await?;

// SAFETY: `url` is a valid URI since URLs are a subset of URIs and `url_object` is a valid URL.
Expand Down Expand Up @@ -195,7 +195,7 @@ pub async fn exec(
Ok(())
}

async fn spawn_trace(address: &NewAddress, jstz_client: &JstzClient) -> Result<()> {
async fn spawn_trace(address: &Address, jstz_client: &JstzClient) -> Result<()> {
let event_source = jstz_client.logs_stream(address);
// need to use mpsc instead of oneshot because of the loop
let (tx, mut rx) = mpsc::channel::<()>(1);
Expand Down
13 changes: 5 additions & 8 deletions crates/jstz_cli/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::{Error, Result};
use anyhow::anyhow;
use jstz_proto::context::new_account::NewAddress;
use jstz_proto::context::account::Address;
use std::{
env,
fmt::{self, Display},
Expand All @@ -13,7 +13,7 @@ const JSTZ_ADDRESS_PREFIXES: [&str; 4] = ["tz1", "tz2", "tz3", "KT1"];

#[derive(Clone, Debug)]
pub enum AddressOrAlias {
Address(NewAddress),
Address(Address),
Alias(String),
}

Expand All @@ -28,7 +28,7 @@ impl FromStr for AddressOrAlias {
if is_jstz_address {
Ok(Self::Address(
address_or_alias
.parse::<NewAddress>()
.parse::<Address>()
.map_err(|e| anyhow!("{}", e))?,
))
} else {
Expand Down Expand Up @@ -102,15 +102,12 @@ mod tests {
let result = AddressOrAlias::from_str(TEST_KT1).unwrap();
assert!(matches!(
result,
AddressOrAlias::Address(NewAddress::SmartFunction(_))
AddressOrAlias::Address(Address::SmartFunction(_))
));

// Test valid tz1 address
let result = AddressOrAlias::from_str(TEST_TZ1).unwrap();
assert!(matches!(
result,
AddressOrAlias::Address(NewAddress::User(_))
));
assert!(matches!(result, AddressOrAlias::Address(Address::User(_))));

// Test alias
let result = AddressOrAlias::from_str(TEST_ALIAS).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions crates/jstz_kernel/src/inbox.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use jstz_core::BinEncodable;
use jstz_proto::context::new_account::NewAddress;
use jstz_proto::context::account::Address;
use jstz_proto::operation::{external::Deposit, ExternalOperation, SignedOperation};
use num_traits::ToPrimitive;
use tezos_crypto_rs::hash::ContractKt1Hash;
Expand Down Expand Up @@ -82,7 +82,7 @@ fn read_transfer(
if is_valid_native_deposit(rt, &ticket, ticketer) {
let amount = ticket.amount().to_u64()?;
let address = tez_ticket.0 .0.to_b58check();
let receiver = NewAddress::from_base58(&address).ok()?;
let receiver = Address::from_base58(&address).ok()?;
let content = Deposit {
inbox_id,
amount,
Expand Down Expand Up @@ -195,7 +195,7 @@ mod test {
use jstz_crypto::smart_function_hash::SmartFunctionHash;
use jstz_mock::message::native_deposit::MockNativeDeposit;
use jstz_mock::{host::JstzMockHost, message::fa_deposit::MockFaDeposit};
use jstz_proto::context::new_account::{Addressable, NewAddress};
use jstz_proto::context::account::{Address, Addressable};
use jstz_proto::operation::external;
use tezos_crypto_rs::hash::{ContractKt1Hash, HashTrait};
use tezos_smart_rollup::types::SmartRollupAddress;
Expand Down Expand Up @@ -299,8 +299,8 @@ mod test {
),
proxy_smart_function.map(|p| {
match p {
NewAddress::User(_) => panic!("Unexpected proxy"),
NewAddress::SmartFunction(sfh) => sfh,
Address::User(_) => panic!("Unexpected proxy"),
Address::SmartFunction(sfh) => sfh,
}
})
);
Expand Down
12 changes: 6 additions & 6 deletions crates/jstz_kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ mod test {
message::{fa_deposit::MockFaDeposit, native_deposit::MockNativeDeposit},
};
use jstz_proto::context::{
new_account::NewAddress,
new_account::{Account, ParsedCode},
account::Address,
account::{Account, ParsedCode},
ticket_table::TicketTable,
};
use tezos_smart_rollup::types::{Contract, PublicKeyHash};
Expand Down Expand Up @@ -95,7 +95,7 @@ mod test {
let amount = Account::balance(
host.rt(),
tx,
&NewAddress::User(jstz_crypto::public_key_hash::PublicKeyHash::Tz1(
&Address::User(jstz_crypto::public_key_hash::PublicKeyHash::Tz1(
tz1.into(),
)),
)
Expand All @@ -118,7 +118,7 @@ mod test {
let proxy = crate::executor::smart_function::Script::deploy(
host.rt(),
tx,
&NewAddress::User(
&Address::User(
jstz_crypto::public_key_hash::PublicKeyHash::from_base58(MOCK_SOURCE)
.unwrap(),
),
Expand All @@ -142,7 +142,7 @@ mod test {
let proxy_balance = TicketTable::get_balance(
host.rt(),
tx,
&NewAddress::SmartFunction(proxy),
&Address::SmartFunction(proxy),
&ticket_hash,
)
.unwrap();
Expand Down Expand Up @@ -173,7 +173,7 @@ mod test {
let proxy_balance = TicketTable::get_balance(
host.rt(),
&mut tx,
&NewAddress::SmartFunction(proxy),
&Address::SmartFunction(proxy),
&ticket_hash,
)
.unwrap();
Expand Down
18 changes: 8 additions & 10 deletions crates/jstz_kernel/src/parsing.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use jstz_crypto::public_key_hash::PublicKeyHash;
use jstz_crypto::smart_function_hash::SmartFunctionHash;
use jstz_proto::operation::external::FaDeposit;
use jstz_proto::{context::new_account::NewAddress, Result};
use jstz_proto::{context::account::Address, Result};
use num_traits::ToPrimitive;
use tezos_smart_rollup::michelson::{ticket::FA2_1Ticket, MichelsonContract};
use tezos_smart_rollup::types::{Contract, PublicKeyHash as TezosPublicKeyHash};

pub fn try_parse_contract(contract: &Contract) -> Result<NewAddress> {
pub fn try_parse_contract(contract: &Contract) -> Result<Address> {
match contract {
Contract::Implicit(TezosPublicKeyHash::Ed25519(tz1)) => {
Ok(NewAddress::User(PublicKeyHash::Tz1(tz1.clone().into())))
Ok(Address::User(PublicKeyHash::Tz1(tz1.clone().into())))
}
Contract::Originated(contract_kt1_hash) => Ok(NewAddress::SmartFunction(
Contract::Originated(contract_kt1_hash) => Ok(Address::SmartFunction(
SmartFunctionHash(contract_kt1_hash.clone()),
)),
_ => Err(jstz_proto::Error::InvalidAddress),
Expand All @@ -28,7 +28,7 @@ pub fn try_parse_fa_deposit(

let proxy_smart_function = (proxy_contract)
.map(|c| {
if let addr @ NewAddress::SmartFunction(_) = try_parse_contract(&c.0)? {
if let addr @ Address::SmartFunction(_) = try_parse_contract(&c.0)? {
Ok(addr)
} else {
Err(jstz_proto::Error::AddressTypeMismatch)
Expand Down Expand Up @@ -56,7 +56,7 @@ mod test {

use jstz_crypto::smart_function_hash::SmartFunctionHash;
use jstz_proto::{
context::new_account::{Addressable, NewAddress},
context::account::{Address, Addressable},
operation::external::FaDeposit,
};
use tezos_smart_rollup::{
Expand Down Expand Up @@ -102,10 +102,8 @@ mod test {
let expected = FaDeposit {
inbox_id,
amount,
receiver: NewAddress::User(jstz_mock::account1()),
proxy_smart_function: Some(NewAddress::SmartFunction(
jstz_mock::sf_account1(),
)),
receiver: Address::User(jstz_mock::account1()),
proxy_smart_function: Some(Address::SmartFunction(jstz_mock::sf_account1())),
ticket_hash,
};
assert_eq!(expected, fa_deposit)
Expand Down
2 changes: 1 addition & 1 deletion crates/jstz_node/src/services/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{
use jstz_core::BinEncodable;
use jstz_proto::{
api::KvValue,
context::new_account::{
context::account::{
Account, Nonce, ParsedCode, SmartFunctionAccount, UserAccount,
ACCOUNTS_PATH_PREFIX,
},
Expand Down
Loading