Skip to content

Commit

Permalink
Merge branch 'main' into feat/account-info-restricted-balance
Browse files Browse the repository at this point in the history
  • Loading branch information
dandanlen authored Oct 2, 2023
2 parents 3110687 + b3adda0 commit 6a4e7c9
Show file tree
Hide file tree
Showing 95 changed files with 3,227 additions and 1,925 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tree --no-default-features --depth 1 --edges=features,normal
# - RUSTSEC-2021-0060: This is a transitive dependency of libp2p and will be fixed in an upcoming release.
# - RUSTSEC-2021-0059: This is a transitive dependency of libp2p and will be fixed in an upcoming release.
# - RUSTSEC-2023-0063: This is a transitive dependency of libp2p and it is not used.
# - RUSTSEC-2023-0065: This is a transitive dependency of ethers and is only applicable when using as a server for untrusted traffic.
cf-audit = '''
audit --ignore RUSTSEC-2022-0061
--ignore RUSTSEC-2020-0071
Expand All @@ -49,4 +50,5 @@ audit --ignore RUSTSEC-2022-0061
--ignore RUSTSEC-2021-0060
--ignore RUSTSEC-2021-0059
--ignore RUSTSEC-2023-0063
--ignore RUSTSEC-2023-0065
'''
37 changes: 37 additions & 0 deletions .github/workflows/release-kitkat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release Chainflip KitKat
on:
workflow_dispatch:

concurrency:
group: ${{ github.ref }}-release-kitkat
cancel-in-progress: true

jobs:
check-versions:
uses: ./.github/workflows/_03_check_versions.yml
bins:
needs: [check-versions]
uses: ./.github/workflows/_02_retrieve-bins.yml
secrets: inherit
docker:
needs: [bins]
uses: ./.github/workflows/_24_docker.yml
with:
network: kitkat
environment: prod
publish_public_images: true
secrets: inherit
package:
needs: [bins]
uses: ./.github/workflows/_25_package.yml
with:
network: "kitkat"
environment: prod
secrets: inherit
publish:
needs: [package]
uses: ./.github/workflows/_30_publish.yml
with:
version: "kitkat/"
environment: prod
secrets: inherit
42 changes: 22 additions & 20 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion api/bin/chainflip-broker-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ name = "chainflip-broker-api"
[dependencies]
chainflip-api = { path = "../../lib" }
cf-utilities = { package = "utilities", path = "../../../utilities" }
cf-chains = { path = '../../../state-chain/chains', default-features = false }

anyhow = "1.0.66"
clap = { version = "3.2.23", features = ["derive"] }
Expand Down
65 changes: 2 additions & 63 deletions api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::anyhow;
use cf_utilities::{
task_scope::{task_scope, Scope},
AnyhowRpcError,
Expand All @@ -11,10 +10,8 @@ use chainflip_api::{
};
use clap::Parser;
use futures::FutureExt;
use hex::FromHexError;
use jsonrpsee::{core::async_trait, proc_macros::rpc, server::ServerBuilder};
use serde::{Deserialize, Serialize};
use sp_rpc::number::NumberOrHex;
use std::path::PathBuf;
use tracing::log;

Expand All @@ -24,7 +21,6 @@ use tracing::log;
#[derive(Serialize, Deserialize, Clone)]
pub struct BrokerSwapDepositAddress {
pub address: String,
pub expiry_block: BlockNumber,
pub issued_block: BlockNumber,
pub channel_id: ChannelId,
}
Expand All @@ -33,46 +29,12 @@ impl From<chainflip_api::SwapDepositAddress> for BrokerSwapDepositAddress {
fn from(value: chainflip_api::SwapDepositAddress) -> Self {
Self {
address: value.address,
expiry_block: value.expiry_block,
issued_block: value.issued_block,
channel_id: value.channel_id,
}
}
}

#[derive(Serialize, Deserialize)]
pub struct BrokerCcmChannelMetadata {
gas_budget: NumberOrHex,
message: String,
cf_parameters: Option<String>,
}

fn parse_hex_bytes(string: &str) -> Result<Vec<u8>, FromHexError> {
hex::decode(string.strip_prefix("0x").unwrap_or(string))
}

impl TryInto<CcmChannelMetadata> for BrokerCcmChannelMetadata {
type Error = anyhow::Error;

fn try_into(self) -> Result<CcmChannelMetadata, Self::Error> {
let gas_budget = self
.gas_budget
.try_into()
.map_err(|_| anyhow!("Failed to parse {:?} as gas budget", self.gas_budget))?;
let message =
parse_hex_bytes(&self.message).map_err(|e| anyhow!("Failed to parse message: {e}"))?;

let cf_parameters = self
.cf_parameters
.map(|parameters| parse_hex_bytes(&parameters))
.transpose()
.map_err(|e| anyhow!("Failed to parse cf parameters: {e}"))?
.unwrap_or_default();

Ok(CcmChannelMetadata { gas_budget, message, cf_parameters })
}
}

#[rpc(server, client, namespace = "broker")]
pub trait Rpc {
#[method(name = "registerAccount")]
Expand All @@ -85,7 +47,7 @@ pub trait Rpc {
destination_asset: Asset,
destination_address: String,
broker_commission_bps: BasisPoints,
channel_metadata: Option<BrokerCcmChannelMetadata>,
channel_metadata: Option<CcmChannelMetadata>,
) -> Result<BrokerSwapDepositAddress, AnyhowRpcError>;
}

Expand Down Expand Up @@ -122,10 +84,8 @@ impl RpcServer for RpcServerImpl {
destination_asset: Asset,
destination_address: String,
broker_commission_bps: BasisPoints,
channel_metadata: Option<BrokerCcmChannelMetadata>,
channel_metadata: Option<CcmChannelMetadata>,
) -> Result<BrokerSwapDepositAddress, AnyhowRpcError> {
let channel_metadata = channel_metadata.map(TryInto::try_into).transpose()?;

Ok(self
.api
.broker_api()
Expand Down Expand Up @@ -188,24 +148,3 @@ async fn main() -> anyhow::Result<()> {
})
.await
}

#[cfg(test)]
mod test {
use super::*;
use cf_utilities::assert_err;

#[test]
fn test_decoding() {
assert_eq!(parse_hex_bytes("0x00").unwrap(), vec![0]);
assert_eq!(parse_hex_bytes("cf").unwrap(), vec![0xcf]);
assert_eq!(
parse_hex_bytes("0x00112233445566778899aabbccddeeff").unwrap(),
vec![
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd,
0xee, 0xff
]
);
assert_eq!(parse_hex_bytes("").unwrap(), b"");
assert_err!(parse_hex_bytes("abc"));
}
}
3 changes: 1 addition & 2 deletions api/bin/chainflip-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn run_cli() -> Result<()> {
let api = StateChainApi::connect(scope, cli_settings.state_chain).await?;
match command_line_opts.cmd {
Broker(BrokerSubcommands::RequestSwapDepositAddress(params)) => {
let SwapDepositAddress { address, expiry_block, .. } = api
let SwapDepositAddress { address, .. } = api
.broker_api()
.request_swap_deposit_address(
params.source_asset,
Expand All @@ -71,7 +71,6 @@ async fn run_cli() -> Result<()> {
)
.await?;
println!("Deposit Address: {address}");
println!("Address expires at block {expiry_block}");
},
LiquidityProvider(
LiquidityProviderSubcommands::RequestLiquidityDepositAddress { asset },
Expand Down
7 changes: 1 addition & 6 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ pub trait GovernanceApi: SignedExtrinsicApi {

pub struct SwapDepositAddress {
pub address: String,
pub expiry_block: state_chain_runtime::BlockNumber,
pub issued_block: state_chain_runtime::BlockNumber,
pub channel_id: ChannelId,
}
Expand Down Expand Up @@ -349,10 +348,7 @@ pub trait BrokerApi: SignedExtrinsicApi {

if let Some(state_chain_runtime::RuntimeEvent::Swapping(
pallet_cf_swapping::Event::SwapDepositAddressReady {
deposit_address,
expiry_block,
channel_id,
..
deposit_address, channel_id, ..
},
)) = events.iter().find(|event| {
matches!(
Expand All @@ -364,7 +360,6 @@ pub trait BrokerApi: SignedExtrinsicApi {
}) {
Ok(SwapDepositAddress {
address: deposit_address.to_string(),
expiry_block: *expiry_block,
issued_block: header.number,
channel_id: *channel_id,
})
Expand Down
Loading

0 comments on commit 6a4e7c9

Please sign in to comment.