Skip to content

Commit 4b32795

Browse files
committed
fix(solana): be consistent with json manipulation
Signed-off-by: Guilherme Felipe da Silva <[email protected]>
1 parent a0dccbc commit 4b32795

File tree

4 files changed

+56
-40
lines changed

4 files changed

+56
-40
lines changed

solana/cli/src/gas_service.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
use clap::{Parser, Subcommand};
22
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
33

4-
use crate::config::Config;
4+
use crate::{
5+
config::Config,
6+
types::ChainNameOnAxelar,
7+
utils::{
8+
read_json_file_from_path, write_json_to_file_path, ADDRESS_KEY, CHAINS_KEY,
9+
CONFIG_ACCOUNT_KEY, CONTRACTS_KEY, GAS_SERVICE_KEY,
10+
},
11+
};
512

613
#[derive(Subcommand, Debug)]
714
pub(crate) enum Commands {
@@ -21,19 +28,32 @@ pub(crate) struct InitArgs {
2128
pub(crate) async fn build_instruction(
2229
fee_payer: &Pubkey,
2330
command: Commands,
24-
_config: &Config,
31+
config: &Config,
2532
) -> eyre::Result<Instruction> {
2633
match command {
27-
Commands::Init(init_args) => init(fee_payer, init_args).await,
34+
Commands::Init(init_args) => init(fee_payer, init_args, config).await,
2835
}
2936
}
3037

31-
async fn init(fee_payer: &Pubkey, init_args: InitArgs) -> eyre::Result<Instruction> {
38+
async fn init(
39+
fee_payer: &Pubkey,
40+
init_args: InitArgs,
41+
config: &Config,
42+
) -> eyre::Result<Instruction> {
3243
let program_id = axelar_solana_gas_service::id();
3344
let salt_hash = solana_sdk::keccak::hashv(&[init_args.salt.as_bytes()]).0;
3445
let (config_pda, _bump) =
3546
axelar_solana_gas_service::get_config_pda(&program_id, &salt_hash, &init_args.authority);
3647

48+
let mut chains_info: serde_json::Value = read_json_file_from_path(&config.chains_info_file)?;
49+
chains_info[CHAINS_KEY][ChainNameOnAxelar::from(config.network_type).0][CONTRACTS_KEY]
50+
[GAS_SERVICE_KEY] = serde_json::json!({
51+
ADDRESS_KEY: axelar_solana_gateway::id().to_string(),
52+
CONFIG_ACCOUNT_KEY: config_pda.to_string(),
53+
});
54+
55+
write_json_to_file_path(&chains_info, &config.chains_info_file)?;
56+
3757
Ok(axelar_solana_gas_service::instructions::init_config(
3858
&program_id,
3959
fee_payer,

solana/cli/src/gateway.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use crate::config::Config;
1616
use crate::types::ChainNameOnAxelar;
1717
use crate::utils::{
1818
read_json_file_from_path, write_json_to_file_path, ADDRESS_KEY, AXELAR_KEY, CHAINS_KEY,
19-
CONTRACTS_KEY, DOMAIN_SEPARATOR_KEY, GATEWAY_KEY, GRPC_KEY, MULTISIG_PROVER_KEY,
19+
CONTRACTS_KEY, DOMAIN_SEPARATOR_KEY, GATEWAY_KEY, GRPC_KEY, MINIMUM_ROTATION_DELAY_KEY,
20+
MULTISIG_PROVER_KEY, OPERATOR_KEY, PREVIOUS_SIGNERS_RETENTION_KEY, UPGRADE_AUTHORITY_KEY,
2021
};
2122

2223
#[derive(Subcommand, Debug)]
@@ -187,12 +188,12 @@ async fn init(
187188

188189
chains_info[CHAINS_KEY][ChainNameOnAxelar::from(config.network_type).0][CONTRACTS_KEY]
189190
[GATEWAY_KEY] = json!({
190-
"address": bs58::encode(axelar_solana_gateway::id()).into_string(),
191-
"deployer": fee_payer,
192-
"operator": init_args.operator,
193-
"minimumRotationDelay": init_args.minimum_rotation_delay,
194-
"previousSignersRetention": init_args.previous_signers_retention,
195-
"domainSeparator": domain_separator,
191+
ADDRESS_KEY: axelar_solana_gateway::id().to_string(),
192+
UPGRADE_AUTHORITY_KEY: fee_payer.to_string(),
193+
OPERATOR_KEY: init_args.operator.to_string(),
194+
MINIMUM_ROTATION_DELAY_KEY: init_args.minimum_rotation_delay,
195+
PREVIOUS_SIGNERS_RETENTION_KEY: init_args.previous_signers_retention,
196+
DOMAIN_SEPARATOR_KEY: domain_separator,
196197
});
197198

198199
write_json_to_file_path(&chains_info, &config.chains_info_file)?;

solana/cli/src/its.rs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ use std::{fs::File, io::Write, time::SystemTime};
22

33
use axelar_solana_its::state;
44
use clap::{Parser, Subcommand};
5-
use serde::{Deserialize, Serialize};
5+
use serde::Deserialize;
66
use solana_sdk::instruction::Instruction;
77
use solana_sdk::pubkey::Pubkey;
88

99
use crate::config::Config;
1010
use crate::types::ChainNameOnAxelar;
1111
use crate::utils::{
12-
self, read_json_file_from_path, ADDRESS_KEY, AXELAR_KEY, CHAINS_KEY, CONFIG_ACCOUNT_KEY,
13-
CONTRACTS_KEY, GAS_SERVICE_KEY, ITS_KEY,
12+
encode_its_destination, read_json_file_from_path, write_json_to_file_path, ADDRESS_KEY,
13+
AXELAR_KEY, CHAINS_KEY, CONFIG_ACCOUNT_KEY, CONTRACTS_KEY, GAS_SERVICE_KEY, ITS_KEY,
14+
OPERATOR_KEY, UPGRADE_AUTHORITY_KEY,
1415
};
1516

1617
#[derive(Subcommand, Debug)]
@@ -656,15 +657,6 @@ pub(crate) async fn build_instruction(
656657
}
657658
}
658659

659-
#[derive(Serialize, Deserialize, Debug)]
660-
struct ItsInfo {
661-
address: String,
662-
#[serde(rename = "configAccount")]
663-
config_account: String,
664-
#[serde(rename = "upgradeAuthority")]
665-
upgrade_authority: String,
666-
}
667-
668660
async fn init(
669661
fee_payer: &Pubkey,
670662
init_args: InitArgs,
@@ -673,21 +665,20 @@ async fn init(
673665
let mut chains_info: serde_json::Value = read_json_file_from_path(&config.chains_info_file)?;
674666
let its_hub_address =
675667
String::deserialize(&chains_info[AXELAR_KEY][CONTRACTS_KEY][ITS_KEY][ADDRESS_KEY])?;
676-
677-
let its_info = ItsInfo {
678-
address: axelar_solana_its::id().to_string(),
679-
config_account: axelar_solana_its::find_its_root_pda(
680-
&axelar_solana_gateway::get_gateway_root_config_pda().0,
681-
)
682-
.0
683-
.to_string(),
684-
upgrade_authority: fee_payer.to_string(),
685-
};
668+
let its_root_config = axelar_solana_its::find_its_root_pda(
669+
&axelar_solana_gateway::get_gateway_root_config_pda().0,
670+
)
671+
.0;
686672

687673
chains_info[CHAINS_KEY][ChainNameOnAxelar::from(config.network_type).0][CONTRACTS_KEY]
688-
[ITS_KEY] = serde_json::json!(its_info);
674+
[ITS_KEY] = serde_json::json!({
675+
ADDRESS_KEY: axelar_solana_gateway::id().to_string(),
676+
CONFIG_ACCOUNT_KEY: its_root_config.to_string(),
677+
UPGRADE_AUTHORITY_KEY: fee_payer.to_string(),
678+
OPERATOR_KEY: init_args.operator.to_string(),
679+
});
689680

690-
utils::write_json_to_file_path(&chains_info, &config.chains_info_file)?;
681+
write_json_to_file_path(&chains_info, &config.chains_info_file)?;
691682

692683
Ok(axelar_solana_its::instruction::initialize(
693684
*fee_payer,
@@ -734,7 +725,7 @@ async fn approve_deploy_remote_interchain_token(
734725
config: &Config,
735726
) -> eyre::Result<Instruction> {
736727
let chains_info: serde_json::Value = read_json_file_from_path(&config.chains_info_file)?;
737-
let destination_minter = utils::encode_its_destination(
728+
let destination_minter = encode_its_destination(
738729
&chains_info,
739730
&args.destination_chain,
740731
args.destination_minter,
@@ -845,7 +836,7 @@ async fn deploy_remote_interchain_token_with_minter(
845836
let gas_service = try_infer_gas_service_id(args.gas_service, config)?;
846837
let gas_config_account = try_infer_gas_service_config_account(args.gas_config_account, config)?;
847838
let chains_info: serde_json::Value = read_json_file_from_path(&config.chains_info_file)?;
848-
let destination_minter = utils::encode_its_destination(
839+
let destination_minter = encode_its_destination(
849840
&chains_info,
850841
&args.destination_chain,
851842
args.destination_minter,
@@ -932,7 +923,7 @@ async fn interchain_transfer(
932923
.try_into()?;
933924

934925
let chains_info: serde_json::Value = read_json_file_from_path(&config.chains_info_file)?;
935-
let destination_address = utils::encode_its_destination(
926+
let destination_address = encode_its_destination(
936927
&chains_info,
937928
&args.destination_chain,
938929
args.destination_address,
@@ -967,7 +958,7 @@ async fn call_contract_with_interchain_token(
967958
.as_secs()
968959
.try_into()?;
969960
let chains_info: serde_json::Value = read_json_file_from_path(&config.chains_info_file)?;
970-
let destination_address = utils::encode_its_destination(
961+
let destination_address = encode_its_destination(
971962
&chains_info,
972963
&args.destination_chain,
973964
args.destination_address,
@@ -1004,7 +995,7 @@ async fn call_contract_with_interchain_token_offchain_data(
1004995
.as_secs()
1005996
.try_into()?;
1006997
let chains_info: serde_json::Value = read_json_file_from_path(&config.chains_info_file)?;
1007-
let destination_address = utils::encode_its_destination(
998+
let destination_address = encode_its_destination(
1008999
&chains_info,
10091000
&args.destination_chain,
10101001
args.destination_address,

solana/cli/src/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub(crate) const GATEWAY_KEY: &str = "AxelarGateway";
2424
pub(crate) const GRPC_KEY: &str = "grpc";
2525
pub(crate) const ITS_KEY: &str = "InterchainTokenService";
2626
pub(crate) const MULTISIG_PROVER_KEY: &str = "MultisigProver";
27+
pub(crate) const UPGRADE_AUTHORITY_KEY: &str = "upgradeAuthority";
28+
pub(crate) const OPERATOR_KEY: &str = "operator";
29+
pub(crate) const MINIMUM_ROTATION_DELAY_KEY: &str = "minimumRotationDelay";
30+
pub(crate) const PREVIOUS_SIGNERS_RETENTION_KEY: &str = "previousSignersRetention";
2731

2832
pub(crate) fn read_json_file<T: DeserializeOwned>(file: &File) -> Result<T> {
2933
let reader = std::io::BufReader::new(file);

0 commit comments

Comments
 (0)