Skip to content

Commit

Permalink
chore(application): use from_base64 methods from fleek-crypto to avoi…
Browse files Browse the repository at this point in the history
…d fastcrypto dependency
  • Loading branch information
matthias-wright committed Jul 11, 2023
1 parent 40592d2 commit d2c0a3d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 41 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,6 @@ dependencies = [
"draco-interfaces",
"draco-reputation",
"draco-test-utils",
"fastcrypto",
"fleek-crypto",
"hp-float",
"multiaddr",
Expand Down
1 change: 0 additions & 1 deletion core/application/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ multiaddr = "0.17.1"
draco-interfaces = { path = "../interfaces" }
draco-reputation = { path = "../reputation" }
num-traits.workspace = true
fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "c961a01596a87e76f590c7e43aca9d57106dbbb1" }

# Our libraries
affair.workspace = true
Expand Down
12 changes: 3 additions & 9 deletions core/application/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use draco_interfaces::{
},
BlockExecutionResponse,
};
use fastcrypto::{secp256k1::Secp256k1PublicKey, traits::EncodeDecodeBase64};
use fleek_crypto::{AccountOwnerPublicKey, ClientPublicKey, EthAddress, NodePublicKey, PublicKey};
use hp_float::unsigned::HpUfloat;

Expand Down Expand Up @@ -132,10 +131,8 @@ impl Env<UpdatePerm> {
let mut current_epoch_served_table =
ctx.get_table::<NodePublicKey, CommodityServed>("current_epoch_served");

let protocol_fund_address: AccountOwnerPublicKey =
Secp256k1PublicKey::decode_base64(&genesis.protocol_fund_address)
.unwrap()
.into();
let protocol_fund_address =
AccountOwnerPublicKey::from_base64(&genesis.protocol_fund_address).unwrap();
metadata_table.insert(
Metadata::ProtocolFundAddress,
Value::AccountPublicKey(protocol_fund_address.into()),
Expand Down Expand Up @@ -209,10 +206,7 @@ impl Env<UpdatePerm> {
}

for account in genesis.account {
let public_key: AccountOwnerPublicKey =
Secp256k1PublicKey::decode_base64(&account.public_key)
.unwrap()
.into();
let public_key = AccountOwnerPublicKey::from_base64(&account.public_key).unwrap();
let info = AccountInfo {
flk_balance: account.flk_balance.into(),
stables_balance: account.stables_balance.into(),
Expand Down
32 changes: 7 additions & 25 deletions core/application/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use anyhow::{Context, Result};
use draco_interfaces::types::{
CommodityServed, CommodityTypes, Epoch, NodeInfo, Staking, TotalServed, Worker,
};
use fastcrypto::{
bls12381::min_sig::BLS12381PublicKey, ed25519::Ed25519PublicKey, secp256k1::Secp256k1PublicKey,
traits::EncodeDecodeBase64,
};
use fleek_crypto::AccountOwnerPublicKey;
use fleek_crypto::{AccountOwnerPublicKey, NodeNetworkingPublicKey, NodePublicKey, PublicKey};
use multiaddr::Multiaddr;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -86,36 +82,22 @@ fn test() {

impl From<&GenesisCommittee> for NodeInfo {
fn from(value: &GenesisCommittee) -> Self {
let owner: AccountOwnerPublicKey = Secp256k1PublicKey::decode_base64(&value.owner)
.unwrap()
.into();

let public_key = BLS12381PublicKey::decode_base64(&value.primary_public_key)
.unwrap()
.pubkey
.to_bytes();

let network_key = Ed25519PublicKey::decode_base64(&value.network_key)
.unwrap()
.0
.to_bytes();
let owner = AccountOwnerPublicKey::from_base64(&value.owner).unwrap();
let public_key = NodePublicKey::from_base64(&value.primary_public_key).unwrap();
let network_key = NodeNetworkingPublicKey::from_base64(&value.network_key).unwrap();

let domain: Multiaddr = value.primary_address.parse().unwrap();

let worker = Worker {
public_key: Ed25519PublicKey::decode_base64(&value.worker_public_key)
.unwrap()
.0
.to_bytes()
.into(),
public_key: NodeNetworkingPublicKey::from_base64(&value.worker_public_key).unwrap(),
address: value.worker_address.parse().unwrap(),
mempool: value.worker_mempool.parse().unwrap(),
};

NodeInfo {
owner: owner.into(),
public_key: public_key.into(),
network_key: network_key.into(),
public_key,
network_key,
domain,
workers: [worker].to_vec(),
staked_since: 0,
Expand Down
10 changes: 5 additions & 5 deletions core/rpc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ async fn test_rpc_get_year_start_supply() -> Result<()> {
app.start().await;

// Init rpc service
let port = 30014;
let port = 30015;
let mut rpc = Rpc::init(
RpcConfig::default(),
MockWorker::mempool_socket(),
Expand Down Expand Up @@ -1111,7 +1111,7 @@ async fn test_rpc_get_protocol_fund_address() -> Result<()> {
app.start().await;

// Init rpc service
let port = 30014;
let port = 30016;
let mut rpc = Rpc::init(
RpcConfig::default(),
MockWorker::mempool_socket(),
Expand Down Expand Up @@ -1160,7 +1160,7 @@ async fn test_rpc_get_protocol_params() -> Result<()> {
app.start().await;

// Init rpc service
let port = 30015;
let port = 30017;
let mut rpc = Rpc::init(
RpcConfig::default(),
MockWorker::mempool_socket(),
Expand Down Expand Up @@ -1225,7 +1225,7 @@ async fn test_rpc_get_total_served() -> Result<()> {
app.start().await;

// Init rpc service
let port = 30016;
let port = 30018;
let mut rpc = Rpc::init(
RpcConfig::default(),
MockWorker::mempool_socket(),
Expand Down Expand Up @@ -1284,7 +1284,7 @@ async fn test_rpc_get_commodity_served() -> Result<()> {
app.start().await;

// Init rpc service
let port = 30017;
let port = 30019;
let mut rpc = Rpc::init(
RpcConfig::default(),
MockWorker::mempool_socket(),
Expand Down

0 comments on commit d2c0a3d

Please sign in to comment.