Skip to content

Commit

Permalink
fix(node): remove locked_balance from Balance (#3886)
Browse files Browse the repository at this point in the history
* fix(node): remove `locked_balance` from `Balance`

* chore(node): update open rpc spec

* chore(sdk+apps): remove unused `lockedBalance`

* fix(node): remove `request_add_stake_with_locked_coin` from exchange integration guide
  • Loading branch information
muXxer authored Nov 5, 2024
1 parent d891762 commit 112e777
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const findBalanceFactory = (
totalBalance: '100',
coinObjectCount: 2,
coinType: '0x2::iota::IOTA',
lockedBalance: {},
},
});
}
Expand All @@ -33,7 +32,6 @@ const findBalanceFactory = (
totalBalance: '0',
coinObjectCount: 0,
coinType: '0x2::iota::IOTA',
lockedBalance: {},
},
});
};
Expand Down
1 change: 0 additions & 1 deletion apps/wallet/src/ui/app/accounts-finder/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export const getEmptyBalance = (coinType: string): CoinBalance => ({
coinType: coinType,
coinObjectCount: 0,
totalBalance: '0',
lockedBalance: {},
});
4 changes: 0 additions & 4 deletions crates/iota-cluster-test/src/test_case/coin_index_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::collections::HashMap;

use async_trait::async_trait;
use iota_core::test_utils::compile_managed_coin_package;
use iota_json::IotaJsonValue;
Expand Down Expand Up @@ -226,13 +224,11 @@ impl TestCaseImpl for CoinIndexTest {
coin_type: iota_type_str.into(),
coin_object_count: old_coin_object_count,
total_balance,
locked_balance: HashMap::new(),
},
Balance {
coin_type: coin_type_str.clone(),
coin_object_count: 1,
total_balance: 10000,
locked_balance: HashMap::new(),
},
];
// Comes with asc order.
Expand Down
3 changes: 1 addition & 2 deletions crates/iota-indexer/src/models/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::{collections::HashMap, sync::Arc};
use std::sync::Arc;

use diesel::prelude::*;
use iota_json_rpc::coin_api::parse_to_struct_tag;
Expand Down Expand Up @@ -541,7 +541,6 @@ impl TryFrom<CoinBalance> for Balance {
coin_object_count: c.coin_num as usize,
// TODO: deal with overflow
total_balance: c.coin_balance as u128,
locked_balance: HashMap::default(),
})
}
}
Expand Down
9 changes: 1 addition & 8 deletions crates/iota-json-rpc-types/src/iota_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::collections::HashMap;

use iota_types::{
base_types::{EpochId, ObjectDigest, ObjectID, ObjectRef, SequenceNumber, TransactionDigest},
base_types::{ObjectDigest, ObjectID, ObjectRef, SequenceNumber, TransactionDigest},
coin::CoinMetadata,
error::IotaError,
iota_serde::{BigInt, SequenceNumber as AsSequenceNumber},
Expand All @@ -28,10 +26,6 @@ pub struct Balance {
#[schemars(with = "BigInt<u128>")]
#[serde_as(as = "BigInt<u128>")]
pub total_balance: u128,
// TODO: This should be removed
#[schemars(with = "HashMap<BigInt<u64>, BigInt<u128>>")]
#[serde_as(as = "HashMap<BigInt<u64>, BigInt<u128>>")]
pub locked_balance: HashMap<EpochId, u128>,
}

impl Balance {
Expand All @@ -40,7 +34,6 @@ impl Balance {
coin_type,
coin_object_count: 0,
total_balance: 0,
locked_balance: HashMap::new(),
}
}
}
Expand Down
18 changes: 4 additions & 14 deletions crates/iota-json-rpc/src/coin_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ impl CoinReadApiServer for CoinReadApi {
coin_type: coin_type_tag.to_string(),
coin_object_count: balance.num_coins as usize,
total_balance: balance.balance as u128,
// note: LockedCoin is deprecated
locked_balance: Default::default(),
})
}
.trace()
Expand All @@ -192,14 +190,10 @@ impl CoinReadApiServer for CoinReadApi {
})?;
Ok(all_balance
.iter()
.map(|(coin_type, balance)| {
Balance {
coin_type: coin_type.to_string(),
coin_object_count: balance.num_coins as usize,
total_balance: balance.balance as u128,
// note: LockedCoin is deprecated
locked_balance: Default::default(),
}
.map(|(coin_type, balance)| Balance {
coin_type: coin_type.to_string(),
coin_object_count: balance.num_coins as usize,
total_balance: balance.balance as u128,
})
.collect())
}
Expand Down Expand Up @@ -961,7 +955,6 @@ mod tests {
coin_type: gas_coin.coin_type,
coin_object_count: 9,
total_balance: 7,
locked_balance: Default::default()
});
}

Expand Down Expand Up @@ -994,7 +987,6 @@ mod tests {
coin_type: coin.coin_type,
coin_object_count: 11,
total_balance: 10,
locked_balance: Default::default()
});
}

Expand Down Expand Up @@ -1108,13 +1100,11 @@ mod tests {
coin_type: gas_coin.coin_type,
coin_object_count: 9,
total_balance: 7,
locked_balance: Default::default(),
},
Balance {
coin_type: usdc_coin.coin_type,
coin_object_count: 11,
total_balance: 10,
locked_balance: Default::default(),
},
];
// This is because the underlying result is a hashmap, so order is not
Expand Down
13 changes: 2 additions & 11 deletions crates/iota-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3192,8 +3192,7 @@
{
"coinType": "0x2::iota::IOTA",
"coinObjectCount": 15,
"totalBalance": "3000000000",
"lockedBalance": {}
"totalBalance": "3000000000"
}
]
}
Expand Down Expand Up @@ -3370,8 +3369,7 @@
"value": {
"coinType": "0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC",
"coinObjectCount": 15,
"totalBalance": "15",
"lockedBalance": {}
"totalBalance": "15"
}
}
}
Expand Down Expand Up @@ -5739,7 +5737,6 @@
"required": [
"coinObjectCount",
"coinType",
"lockedBalance",
"totalBalance"
],
"properties": {
Expand All @@ -5751,12 +5748,6 @@
"coinType": {
"type": "string"
},
"lockedBalance": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/BigInt_for_uint128"
}
},
"totalBalance": {
"$ref": "#/components/schemas/BigInt_for_uint128"
}
Expand Down
8 changes: 1 addition & 7 deletions crates/iota-open-rpc/src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::{
collections::{BTreeMap, HashMap},
ops::Range,
str::FromStr,
};
use std::{collections::BTreeMap, ops::Range, str::FromStr};

use fastcrypto::traits::EncodeDecodeBase64;
use iota_json::IotaJsonValue;
Expand Down Expand Up @@ -785,7 +781,6 @@ impl RpcExampleProvider {
coin_type: "0x2::iota::IOTA".to_string(),
coin_object_count: 15,
total_balance: 3000000000,
locked_balance: HashMap::new(),
};
Examples::new("iotax_getAllBalances", vec![ExamplePairing::new(
"Gets all balances for the address in the request.",
Expand Down Expand Up @@ -834,7 +829,6 @@ impl RpcExampleProvider {
coin_type: coin_type.clone(),
coin_object_count: 15,
total_balance: 15,
locked_balance: HashMap::new(),
};

Examples::new("iotax_getBalance", vec![ExamplePairing::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ The response is a JSON object that includes the `totalBalance` for the address:
"result":{
"coinType":"0x2::iota::IOTA",
"coinObjectCount":40,
"totalBalance":10000000000,
"lockedBalance":{}
"totalBalance":10000000000
},
"id":1
}
Expand Down
18 changes: 1 addition & 17 deletions docs/content/references/exchange-integration-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ The response is a JSON object that includes the totalBalance for the address:
"result": {
"coinType": "0x2::iota::IOTA",
"coinObjectCount": 40,
"totalBalance": 10000000000,
"lockedBalance": {}
"totalBalance": 10000000000
},
"id": 1
}
Expand Down Expand Up @@ -292,21 +291,6 @@ public fun request_add_stake_mul_coin(
}
```

- `request_add_stake_with_locked_coin`
Add user stake to a validator's staking pool using a locked IOTA coin.

```move
public fun request_add_stake_with_locked_coin(
self: &mut IOTASystemState,
stake: LockedCoin<IOTA>,
validator_address: address,
ctx: &mut TxContext,
) {
let (balance, lock) = locked_coin::into_balance(stake);
validator_set::request_add_stake(&mut self.validators, validator_address, balance, option::some(lock), ctx);
}
```

- `request_withdraw_stake`
Withdraw some portion of a user stake from a validator's staking pool.

Expand Down
1 change: 0 additions & 1 deletion sdk/dapp-kit/test/hooks/useIotaClientQueries.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const MOCK_GET_All_BALANCE_RESULT_DATA = [
coinType: '0x2::iota::IOTA',
coinObjectCount: 1,
totalBalance: '100000',
lockedBalance: {},
},
];
const MOCK_QUERY_TRANSACTION_BLOCK_RESULT_DATA = {
Expand Down
2 changes: 0 additions & 2 deletions sdk/graphql-transport/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export const RPC_METHODS: {
coinType: toShortTypeString(balance.coinType?.repr!),
coinObjectCount: balance.coinObjectCount!,
totalBalance: balance.totalBalance,
lockedBalance: {},
};
},

Expand All @@ -206,7 +205,6 @@ export const RPC_METHODS: {
coinType: toShortTypeString(balance.coinType?.repr!),
coinObjectCount: balance.coinObjectCount!,
totalBalance: balance.totalBalance,
lockedBalance: {},
}));
},
async getCoinMetadata(transport, inputs) {
Expand Down
1 change: 0 additions & 1 deletion sdk/typescript/src/client/types/coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export type CoinBalance = {
coinType: string;
coinObjectCount: number;
totalBalance: string;
lockedBalance: Record<string, string>;
};
3 changes: 0 additions & 3 deletions sdk/typescript/src/client/types/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export interface AddressMetrics {
export interface Balance {
coinObjectCount: number;
coinType: string;
lockedBalance: {
[key: string]: string;
};
totalBalance: string;
}
export interface BalanceChange {
Expand Down

0 comments on commit 112e777

Please sign in to comment.