cosmwasm: Rename accounting -> accountant

Also change wormchain -> global.
This commit is contained in:
Chirantan Ekbote 2023-01-18 18:06:13 +09:00 committed by Evan Gray
parent 1f939ea2dd
commit dd95954fc3
27 changed files with 78 additions and 78 deletions

54
cosmwasm/Cargo.lock generated
View File

@ -3,7 +3,7 @@
version = 3 version = 3
[[package]] [[package]]
name = "accounting" name = "accountant"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
@ -926,6 +926,32 @@ version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
[[package]]
name = "global-accountant"
version = "0.1.0"
dependencies = [
"accountant",
"anyhow",
"base64",
"cosmwasm-schema",
"cosmwasm-std",
"cosmwasm-storage",
"cw-multi-test",
"cw-storage-plus",
"cw2",
"cw_transcode",
"hex",
"schemars",
"serde",
"serde-json-wasm",
"serde_wormhole",
"thiserror",
"tinyvec",
"token-bridge-terra-2",
"wormhole-bindings",
"wormhole-core",
]
[[package]] [[package]]
name = "group" name = "group"
version = "0.10.0" version = "0.10.0"
@ -2247,32 +2273,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "wormchain-accounting"
version = "0.1.0"
dependencies = [
"accounting",
"anyhow",
"base64",
"cosmwasm-schema",
"cosmwasm-std",
"cosmwasm-storage",
"cw-multi-test",
"cw-storage-plus",
"cw2",
"cw_transcode",
"hex",
"schemars",
"serde",
"serde-json-wasm",
"serde_wormhole",
"thiserror",
"tinyvec",
"token-bridge-terra-2",
"wormhole-bindings",
"wormhole-core",
]
[[package]] [[package]]
name = "wormhole-bindings" name = "wormhole-bindings"
version = "0.1.0" version = "0.1.0"

View File

@ -6,8 +6,8 @@ members = [
"contracts/token-bridge", "contracts/token-bridge",
"contracts/shutdown-token-bridge", "contracts/shutdown-token-bridge",
"contracts/mock-bridge-integration", "contracts/mock-bridge-integration",
"packages/accounting", "packages/accountant",
"contracts/wormchain-accounting", "contracts/global-accountant",
"packages/wormhole-bindings", "packages/wormhole-bindings",
"packages/cw_transcode", "packages/cw_transcode",
] ]
@ -28,12 +28,12 @@ incremental = false
overflow-checks = true overflow-checks = true
[patch.crates-io] [patch.crates-io]
accounting = { path = "packages/accounting" } accountant = { path = "packages/accountant" }
cw_transcode = { path = "packages/cw_transcode" } cw_transcode = { path = "packages/cw_transcode" }
cw20-wrapped-2 = { path = "contracts/cw20-wrapped" } cw20-wrapped-2 = { path = "contracts/cw20-wrapped" }
serde_wormhole = { path = "../sdk/rust/serde_wormhole" } serde_wormhole = { path = "../sdk/rust/serde_wormhole" }
token-bridge-terra-2 = { path = "contracts/token-bridge" } token-bridge-terra-2 = { path = "contracts/token-bridge" }
wormchain-accounting = { path = "contracts/wormchain-accounting" } global-accountant = { path = "contracts/global-accountant" }
wormhole-bindings = { path = "packages/wormhole-bindings" } wormhole-bindings = { path = "packages/wormhole-bindings" }
wormhole-bridge-terra-2 = { path = "contracts/wormhole" } wormhole-bridge-terra-2 = { path = "contracts/wormhole" }
wormhole-core = { path = "../sdk/rust/core" } wormhole-core = { path = "../sdk/rust/core" }

View File

@ -1,5 +1,5 @@
[package] [package]
name = "wormchain-accounting" name = "global-accountant"
version = "0.1.0" version = "0.1.0"
authors = ["Wormhole Project Contributors"] authors = ["Wormhole Project Contributors"]
edition = "2021" edition = "2021"
@ -13,7 +13,7 @@ backtraces = ["cosmwasm-std/backtraces"]
library = [] library = []
[dependencies] [dependencies]
accounting = "0.1.0" accountant = "0.1.0"
anyhow = "1" anyhow = "1"
base64 = "0.13" base64 = "0.13"
cosmwasm-schema = "1" cosmwasm-schema = "1"

View File

@ -1,7 +1,7 @@
use cosmwasm_schema::write_api; use cosmwasm_schema::write_api;
use cosmwasm_std::Empty; use cosmwasm_std::Empty;
use wormchain_accounting::msg::{ExecuteMsg, QueryMsg}; use global_accountant::msg::{ExecuteMsg, QueryMsg};
fn main() { fn main() {
write_api! { write_api! {

View File

@ -1,5 +1,5 @@
{ {
"contract_name": "wormchain-accounting", "contract_name": "global-accountant",
"contract_version": "0.1.0", "contract_version": "0.1.0",
"idl_version": "1.0.0", "idl_version": "1.0.0",
"instantiate": { "instantiate": {

View File

@ -1,6 +1,6 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use accounting::{ use accountant::{
query_balance, query_modification, query_balance, query_modification,
state::{account, transfer, Modification, TokenAddress, Transfer}, state::{account, transfer, Modification, TokenAddress, Transfer},
validate_transfer, validate_transfer,
@ -37,7 +37,7 @@ use crate::{
}; };
// version info for migration info // version info for migration info
const CONTRACT_NAME: &str = "crates.io:wormchain-accounting"; const CONTRACT_NAME: &str = "crates.io:global-accountant";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg_attr(not(feature = "library"), entry_point)] #[cfg_attr(not(feature = "library"), entry_point)]
@ -241,7 +241,7 @@ fn handle_observation(
"unknown emitter address" "unknown emitter address"
); );
accounting::commit_transfer( accountant::commit_transfer(
deps.branch(), deps.branch(),
Transfer { Transfer {
key: tx_key, key: tx_key,
@ -287,7 +287,7 @@ fn modify_balance(
let msg: Modification = from_binary(&modification).context("failed to parse `Modification`")?; let msg: Modification = from_binary(&modification).context("failed to parse `Modification`")?;
let event = let event =
accounting::modify_balance(deps, msg).context("failed to modify account balance")?; accountant::modify_balance(deps, msg).context("failed to modify account balance")?;
Ok(Response::new() Ok(Response::new()
.add_attribute("action", "modify_balance") .add_attribute("action", "modify_balance")
@ -471,7 +471,7 @@ fn handle_tokenbridge_vaa(
key: key.clone(), key: key.clone(),
data, data,
}; };
let evt = accounting::commit_transfer(deps.branch(), tx) let evt = accountant::commit_transfer(deps.branch(), tx)
.with_context(|| format!("failed to commit transfer for key {key}"))?; .with_context(|| format!("failed to commit transfer for key {key}"))?;
PENDING_TRANSFERS.remove(deps.storage, key); PENDING_TRANSFERS.remove(deps.storage, key);
@ -532,12 +532,12 @@ fn query_all_accounts(
let l = lim let l = lim
.try_into() .try_into()
.map_err(|_| ConversionOverflowError::new("u32", "usize", lim.to_string()))?; .map_err(|_| ConversionOverflowError::new("u32", "usize", lim.to_string()))?;
accounting::query_all_accounts(deps, start_after) accountant::query_all_accounts(deps, start_after)
.take(l) .take(l)
.collect::<StdResult<Vec<_>>>() .collect::<StdResult<Vec<_>>>()
.map(|accounts| AllAccountsResponse { accounts }) .map(|accounts| AllAccountsResponse { accounts })
} else { } else {
accounting::query_all_accounts(deps, start_after) accountant::query_all_accounts(deps, start_after)
.collect::<StdResult<Vec<_>>>() .collect::<StdResult<Vec<_>>>()
.map(|accounts| AllAccountsResponse { accounts }) .map(|accounts| AllAccountsResponse { accounts })
} }
@ -552,7 +552,7 @@ fn query_all_transfers(
let l = lim let l = lim
.try_into() .try_into()
.map_err(|_| ConversionOverflowError::new("u32", "usize", lim.to_string()))?; .map_err(|_| ConversionOverflowError::new("u32", "usize", lim.to_string()))?;
accounting::query_all_transfers(deps, start_after) accountant::query_all_transfers(deps, start_after)
.map(|res| { .map(|res| {
res.and_then(|t| { res.and_then(|t| {
let digest = DIGESTS.load( let digest = DIGESTS.load(
@ -571,7 +571,7 @@ fn query_all_transfers(
.collect::<StdResult<Vec<_>>>() .collect::<StdResult<Vec<_>>>()
.map(|transfers| AllTransfersResponse { transfers }) .map(|transfers| AllTransfersResponse { transfers })
} else { } else {
accounting::query_all_transfers(deps, start_after) accountant::query_all_transfers(deps, start_after)
.map(|res| { .map(|res| {
res.and_then(|t| { res.and_then(|t| {
let digest = DIGESTS.load( let digest = DIGESTS.load(
@ -637,12 +637,12 @@ fn query_all_modifications(
let l = lim let l = lim
.try_into() .try_into()
.map_err(|_| ConversionOverflowError::new("u32", "usize", lim.to_string()))?; .map_err(|_| ConversionOverflowError::new("u32", "usize", lim.to_string()))?;
accounting::query_all_modifications(deps, start_after) accountant::query_all_modifications(deps, start_after)
.take(l) .take(l)
.collect::<StdResult<Vec<_>>>() .collect::<StdResult<Vec<_>>>()
.map(|modifications| AllModificationsResponse { modifications }) .map(|modifications| AllModificationsResponse { modifications })
} else { } else {
accounting::query_all_modifications(deps, start_after) accountant::query_all_modifications(deps, start_after)
.collect::<StdResult<Vec<_>>>() .collect::<StdResult<Vec<_>>>()
.map(|modifications| AllModificationsResponse { modifications }) .map(|modifications| AllModificationsResponse { modifications })
} }
@ -690,7 +690,7 @@ fn query_transfer_status(
key.sequence(), key.sequence(),
), ),
)? { )? {
let data = accounting::query_transfer(deps, key.clone())?; let data = accountant::query_transfer(deps, key.clone())?;
Ok(TransferStatus::Committed { data, digest }) Ok(TransferStatus::Committed { data, digest })
} else if let Some(data) = PENDING_TRANSFERS.may_load(deps.storage, key.clone())? { } else if let Some(data) = PENDING_TRANSFERS.may_load(deps.storage, key.clone())? {
Ok(TransferStatus::Pending(tinyvec_to_vec(data))) Ok(TransferStatus::Pending(tinyvec_to_vec(data)))

View File

@ -1,4 +1,4 @@
use accounting::state::{account, transfer, Account, Modification, Transfer}; use accountant::state::{account, transfer, Account, Modification, Transfer};
use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Binary; use cosmwasm_std::Binary;
use serde_wormhole::RawMessage; use serde_wormhole::RawMessage;

View File

@ -1,4 +1,4 @@
use accounting::state::transfer; use accountant::state::transfer;
use cosmwasm_schema::cw_serde; use cosmwasm_schema::cw_serde;
use cosmwasm_std::Binary; use cosmwasm_std::Binary;
use cw_storage_plus::Map; use cw_storage_plus::Map;

View File

@ -1,8 +1,8 @@
mod helpers; mod helpers;
use cosmwasm_std::{to_binary, Event}; use cosmwasm_std::{to_binary, Event};
use global_accountant::msg::ChainRegistrationResponse;
use helpers::*; use helpers::*;
use wormchain_accounting::msg::ChainRegistrationResponse;
use wormhole::{ use wormhole::{
token::{Action, GovernancePacket}, token::{Action, GovernancePacket},
vaa::Body, vaa::Body,

View File

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
use accounting::state::{account, transfer, Modification}; use accountant::state::{account, transfer, Modification};
use cosmwasm_schema::cw_serde; use cosmwasm_schema::cw_serde;
use cosmwasm_std::{ use cosmwasm_std::{
testing::{MockApi, MockStorage}, testing::{MockApi, MockStorage},
@ -9,8 +9,7 @@ use cosmwasm_std::{
use cw_multi_test::{ use cw_multi_test::{
App, AppBuilder, AppResponse, BankKeeper, ContractWrapper, Executor, WasmKeeper, App, AppBuilder, AppResponse, BankKeeper, ContractWrapper, Executor, WasmKeeper,
}; };
use serde::Serialize; use global_accountant::{
use wormchain_accounting::{
msg::{ msg::{
AllAccountsResponse, AllModificationsResponse, AllPendingTransfersResponse, AllAccountsResponse, AllModificationsResponse, AllPendingTransfersResponse,
AllTransfersResponse, BatchTransferStatusResponse, ChainRegistrationResponse, ExecuteMsg, AllTransfersResponse, BatchTransferStatusResponse, ChainRegistrationResponse, ExecuteMsg,
@ -18,6 +17,7 @@ use wormchain_accounting::{
}, },
state, state,
}; };
use serde::Serialize;
use wormhole::{ use wormhole::{
token::{Action, GovernancePacket}, token::{Action, GovernancePacket},
vaa::{Body, Header, Signature}, vaa::{Body, Header, Signature},
@ -253,10 +253,10 @@ pub fn proper_instantiate() -> (fake::WormholeKeeper, Contract) {
let wh = fake::WormholeKeeper::new(); let wh = fake::WormholeKeeper::new();
let mut app = fake_app(wh.clone()); let mut app = fake_app(wh.clone());
let accounting_id = app.store_code(Box::new(ContractWrapper::new( let accountant_id = app.store_code(Box::new(ContractWrapper::new(
wormchain_accounting::contract::execute, global_accountant::contract::execute,
wormchain_accounting::contract::instantiate, global_accountant::contract::instantiate,
wormchain_accounting::contract::query, global_accountant::contract::query,
))); )));
// We want the contract to be able to upgrade itself, which means we have to set the contract // We want the contract to be able to upgrade itself, which means we have to set the contract
@ -278,11 +278,11 @@ pub fn proper_instantiate() -> (fake::WormholeKeeper, Contract) {
// can't use it here. Maybe something to bring up with upstream. // can't use it here. Maybe something to bring up with upstream.
let addr = app let addr = app
.instantiate_contract( .instantiate_contract(
accounting_id, accountant_id,
Addr::unchecked(ADMIN), Addr::unchecked(ADMIN),
&Empty {}, &Empty {},
&[], &[],
"accounting", "accountant",
Some("contract0".into()), Some("contract0".into()),
) )
.unwrap(); .unwrap();

View File

@ -1,9 +1,9 @@
mod helpers; mod helpers;
use accounting::state::transfer; use accountant::state::transfer;
use cosmwasm_std::{to_binary, Uint256}; use cosmwasm_std::{to_binary, Uint256};
use global_accountant::msg::Observation;
use helpers::*; use helpers::*;
use wormchain_accounting::msg::Observation;
use wormhole::{token::Message, Address, Amount, Chain}; use wormhole::{token::Message, Address, Amount, Chain};
fn create_observation() -> Observation { fn create_observation() -> Observation {

View File

@ -1,6 +1,6 @@
mod helpers; mod helpers;
use accounting::state::{account, Kind, Modification}; use accountant::state::{account, Kind, Modification};
use cosmwasm_std::{to_binary, Event, Uint256}; use cosmwasm_std::{to_binary, Event, Uint256};
use helpers::*; use helpers::*;

View File

@ -2,13 +2,13 @@ mod helpers;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use accounting::state::{ use accountant::state::{
account::{self, Balance}, account::{self, Balance},
transfer, Kind, Modification, Transfer, transfer, Kind, Modification, Transfer,
}; };
use cosmwasm_std::{to_binary, Uint256}; use cosmwasm_std::{to_binary, Uint256};
use global_accountant::msg::TransferStatus;
use helpers::*; use helpers::*;
use wormchain_accounting::msg::TransferStatus;
use wormhole::{token::Message, vaa::Body, Address, Amount}; use wormhole::{token::Message, vaa::Body, Address, Amount};
use wormhole_bindings::fake; use wormhole_bindings::fake;

View File

@ -2,11 +2,11 @@ mod helpers;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use accounting::state::{account, transfer, Kind, Modification, TokenAddress}; use accountant::state::{account, transfer, Kind, Modification, TokenAddress};
use cosmwasm_std::{from_binary, to_binary, Binary, Event, Uint256}; use cosmwasm_std::{from_binary, to_binary, Binary, Event, Uint256};
use cw_multi_test::AppResponse; use cw_multi_test::AppResponse;
use global_accountant::msg::{Observation, ObservationStatus, SubmitObservationResponse};
use helpers::*; use helpers::*;
use wormchain_accounting::msg::{Observation, ObservationStatus, SubmitObservationResponse};
use wormhole::{ use wormhole::{
token::Message, token::Message,
vaa::{Body, Header}, vaa::{Body, Header},

View File

@ -1,10 +1,10 @@
mod helpers; mod helpers;
use accounting::state::{transfer, TokenAddress}; use accountant::state::{transfer, TokenAddress};
use cosmwasm_std::{from_binary, to_binary, Binary, Event, Uint256}; use cosmwasm_std::{from_binary, to_binary, Binary, Event, Uint256};
use global_accountant::msg::{Observation, ObservationStatus, SubmitObservationResponse};
use helpers::*; use helpers::*;
use serde_wormhole::RawMessage; use serde_wormhole::RawMessage;
use wormchain_accounting::msg::{Observation, ObservationStatus, SubmitObservationResponse};
use wormhole::{ use wormhole::{
token::Message, token::Message,
vaa::{Body, Header, Vaa}, vaa::{Body, Header, Vaa},

View File

@ -5,8 +5,8 @@ use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Empty, Env, Event, MessageInfo, Response, StdResult, to_binary, Binary, Deps, DepsMut, Empty, Env, Event, MessageInfo, Response, StdResult,
}; };
use cw_multi_test::ContractWrapper; use cw_multi_test::ContractWrapper;
use global_accountant::msg::Upgrade;
use helpers::*; use helpers::*;
use wormchain_accounting::msg::Upgrade;
use wormhole_bindings::WormholeQuery; use wormhole_bindings::WormholeQuery;
pub fn instantiate( pub fn instantiate(

View File

@ -22,7 +22,7 @@ const artifacts = [
"mock_bridge_integration_2.wasm", "mock_bridge_integration_2.wasm",
"shutdown_core_bridge_cosmwasm.wasm", "shutdown_core_bridge_cosmwasm.wasm",
"shutdown_token_bridge_cosmwasm.wasm", "shutdown_token_bridge_cosmwasm.wasm",
"wormchain_accounting.wasm", "global_accountant.wasm",
]; ];
/* Check that the artifact folder contains all the wasm files we expect and nothing else */ /* Check that the artifact folder contains all the wasm files we expect and nothing else */

View File

@ -1,5 +1,5 @@
[package] [package]
name = "accounting" name = "accountant"
version = "0.1.0" version = "0.1.0"
authors = ["Wormhole Project Contributors"] authors = ["Wormhole Project Contributors"]
edition = "2021" edition = "2021"

View File

@ -13,7 +13,7 @@ use crate::{
}, },
}; };
/// Instantiate the on-chain state for accounting. Unlike other methods in this crate, /// Instantiate the on-chain state for accountant. Unlike other methods in this crate,
/// `instantiate` does not perform any validation of the data in `init`. /// `instantiate` does not perform any validation of the data in `init`.
pub fn instantiate<C: CustomQuery>(deps: DepsMut<C>, init: Instantiate) -> anyhow::Result<Event> { pub fn instantiate<C: CustomQuery>(deps: DepsMut<C>, init: Instantiate) -> anyhow::Result<Event> {
let num_accounts = init.accounts.len(); let num_accounts = init.accounts.len();
@ -72,7 +72,7 @@ pub fn validate_transfer<C: CustomQuery>(deps: Deps<C>, t: &Transfer) -> anyhow:
/// ///
/// ``` /// ```
/// # fn example() -> anyhow::Result<()> { /// # fn example() -> anyhow::Result<()> {
/// # use accounting::{ /// # use accountant::{
/// # commit_transfer, /// # commit_transfer,
/// # state::{transfer, Transfer}, /// # state::{transfer, Transfer},
/// # TransferError, /// # TransferError,
@ -201,7 +201,7 @@ pub enum ModifyBalanceError {
/// ///
/// ``` /// ```
/// # fn example() { /// # fn example() {
/// # use accounting::{ /// # use accountant::{
/// # modify_balance, /// # modify_balance,
/// # state::{Kind, Modification}, /// # state::{Kind, Modification},
/// # ModifyBalanceError, /// # ModifyBalanceError,
@ -405,7 +405,7 @@ mod tests {
} }
#[test] #[test]
fn instantiate_accounting() { fn instantiate_accountant() {
let mut deps = mock_dependencies(); let mut deps = mock_dependencies();
let count = 3; let count = 3;
let msg = Instantiate { let msg = Instantiate {

View File

@ -12,9 +12,9 @@ pub use account::Account;
pub use addr::TokenAddress; pub use addr::TokenAddress;
pub use transfer::Transfer; pub use transfer::Transfer;
pub const ACCOUNTS: Map<account::Key, account::Balance> = Map::new("accounting/accounts"); pub const ACCOUNTS: Map<account::Key, account::Balance> = Map::new("accountant/accounts");
pub const TRANSFERS: Map<transfer::Key, transfer::Data> = Map::new("accounting/transfers"); pub const TRANSFERS: Map<transfer::Key, transfer::Data> = Map::new("accountant/transfers");
#[cw_serde] #[cw_serde]
#[derive(Eq, PartialOrd, Ord)] #[derive(Eq, PartialOrd, Ord)]
@ -52,4 +52,4 @@ pub struct Modification {
pub reason: String, pub reason: String,
} }
pub const MODIFICATIONS: Map<u64, Modification> = Map::new("accounting/modifications"); pub const MODIFICATIONS: Map<u64, Modification> = Map::new("accountant/modifications");