Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions pallets/afloat/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use sp_runtime::{traits::StaticLookup, Permill};
// use frame_support::traits::OriginTrait;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT summary of 4c39a1 - bf4ad3:

  • Updated CreateAsset to accept either a new asset ID or an existing one.
  • Updated the set_afloat_balance function to take into account the user's current balance and adjust it accordingly.
  • Removed the DebitFlags parameter from the pallet_mapped_assets::Pallet::debit call.

use core::convert::TryInto;
use frame_support::{sp_io::hashing::blake2_256, traits::Time};
use pallet_mapped_assets::DebitFlags;
use pallet_rbac::types::{IdOrVec, RoleBasedAccessControl, RoleId};
use scale_info::prelude::vec;
use sp_runtime::{
Expand Down Expand Up @@ -73,22 +72,22 @@ impl<T: Config> Pallet<T> {
CreateAsset::New { asset_id, min_balance } => {
pallet_mapped_assets::Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
asset_id,
asset_id.clone().into(),
T::Lookup::unlookup(creator.clone()),
min_balance,
)?;
asset_id
asset_id.clone()
},
CreateAsset::Existing { asset_id } => {
ensure!(
pallet_mapped_assets::Pallet::<T>::does_asset_exists(asset_id),
pallet_mapped_assets::Pallet::<T>::does_asset_exist(&asset_id),
Error::<T>::AssetNotFound
);
asset_id
asset_id.clone()
},
};

AfloatAssetId::<T>::put(asset_id.clone());
AfloatAssetId::<T>::put(asset_id);
Ok(())
}
/// This functions sets up the roles for the Afloat pallet.
Expand Down Expand Up @@ -293,7 +292,6 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
let authority = ensure_signed(origin.clone())?;
let asset_id = AfloatAssetId::<T>::get().expect("AfloatAssetId should be set");
let debit_flags = DebitFlags { keep_alive: false, best_effort: true };
ensure!(UserInfo::<T>::contains_key(user_address.clone()), Error::<T>::UserNotFound);

let current_balance = Self::do_get_afloat_balance(user_address.clone());
Expand All @@ -304,7 +302,6 @@ impl<T: Config> Pallet<T> {
&user_address.clone(),
diff,
Some(authority.clone()),
debit_flags,
)?;
} else if current_balance < amount {
let diff = amount - current_balance;
Expand Down
35 changes: 14 additions & 21 deletions pallets/afloat/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate as pallet_afloat;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT summary of afee51 - 513460:

  • Modified the pallets/afloat/src/mock.rs file, adding ConstU128 and BuildStorage to frame_support::traits and sp_runtime::traits respectively.
  • Changed the type of Balance from u64 to u128 in pallet_balances::Config.
  • Added ConstU128 to ExistentialDeposit and ConstU32 to MaxReserves in pallet_balances::Config.
  • Added FreezeIdentifier, MaxFreezes, RuntimeHoldReason, and MaxHolds to pallet_balances::Config.
  • Changed MaxReserves to ConstU32 in pallet_mapped_assets::Config.
  • Added ReserveIdentifier to pallet_mapped_assets::Config.
  • Added code to build genesis storage according to the mock runtime.

use frame_support::{
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64, Currency},
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Currency},
};
use frame_system as system;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand All @@ -25,12 +25,9 @@ parameter_types! {

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
GatedMarketplace: pallet_gated_marketplace::{Pallet, Call, Storage, Event<T>},
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>},
Fruniques: pallet_fruniques::{Pallet, Call, Storage, Event<T>},
Expand All @@ -49,13 +46,12 @@ impl system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand Down Expand Up @@ -157,21 +153,20 @@ impl pallet_uniques::Config for Test {
type Locker = ();
}

parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub const MaxReserves: u32 = 50;
}

impl pallet_balances::Config for Test {
type Balance = u64;
type Balance = u128;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ExistentialDeposit;
type ExistentialDeposit = ConstU128<100>;
type AccountStore = System;
type WeightInfo = ();
type MaxLocks = ();
type MaxReserves = MaxReserves;
type MaxReserves = ConstU32<50>;
type ReserveIdentifier = [u8; 8];
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type MaxHolds = ();
}

parameter_types! {
Expand Down Expand Up @@ -236,16 +231,14 @@ impl pallet_mapped_assets::Config for Test {
type CallbackHandle = AssetsCallbackHandle;
type Extra = ();
type RemoveItemsLimit = ConstU32<5>;
type MaxReserves = MaxReserves;
type ReserveIdentifier = u32;
type Rbac = RBAC;
}

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
// TODO: get initial conf?
let mut t: sp_io::TestExternalities =
frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into();
frame_system::GenesisConfig::<Test>::default().build_storage().unwrap().into();
t.execute_with(|| {
Balances::make_free_balance_be(&1, 100);
Balances::make_free_balance_be(&2, 100);
Expand Down
5 changes: 4 additions & 1 deletion pallets/bitcoin-vaults/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ impl<T: Config> Pallet<T> {
fraction: 0,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT summary of 52376e - 613af6:

  • Added a negative field to the NumberValue struct
  • Changed the type of the integer field in NumberValue from i64 to u64

fraction_length: 0,
exponent: 0,
negative: false,
};
body.push(("threshold".chars().collect::<Vec<char>>(), JsonValue::Number(threshold)));
let vault_signers = vault.cosigners.clone().to_vec();
Expand Down Expand Up @@ -573,16 +574,18 @@ impl<T: Config> Pallet<T> {
let vault = <Vaults<T>>::get(proposal.vault_id.clone())
.ok_or(Self::build_offchain_err(false, "Vault not found"))?;
let amount = NumberValue {
integer: proposal.amount.clone() as i64,
integer: proposal.amount.clone() as u64,
fraction: 0,
fraction_length: 0,
exponent: 0,
negative: false,
};
let fee = NumberValue {
integer: proposal.fee_sat_per_vb.clone().into(),
fraction: 0,
fraction_length: 0,
exponent: 0,
negative: false,
};
let to_address = str::from_utf8(proposal.to_address.as_slice())
.map_err(|_| {
Expand Down
16 changes: 10 additions & 6 deletions pallets/bitcoin-vaults/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,24 @@ pub mod pallet {
/* --- Genesis Structs Section --- */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT summary of 5dfb66 - 5a3332:

  • Added _config field to GenesisConfig struct
  • Changed GenesisConfig to use generic Config type parameter
  • Changed GenesisBuild to BuildGenesisConfig
  • Changed offchain_worker parameter type to BlockNumberFor<T>


#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {
pub struct GenesisConfig<T: Config> {
pub bdk_services_url: Vec<u8>,
#[serde(skip)]
pub _config: sp_std::marker::PhantomData<T>,
}

#[cfg(feature = "std")]
impl Default for GenesisConfig {
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { bdk_services_url: b"https://bdk.hashed.systems".encode() }
Self {
bdk_services_url: b"https://bdk.hashed.systems".encode(),
_config: Default::default(),
}
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
<BDKServicesURL<T>>::put(
BoundedVec::<u8, ConstU32<32>>::try_from(self.bdk_services_url.clone())
Expand Down Expand Up @@ -275,7 +279,7 @@ pub mod pallet {
/// Note that it's not guaranteed for offchain workers to run on EVERY block, there might
/// be cases where some blocks are skipped, or for some the worker runs twice (re-orgs),
/// so the code should be able to handle that.
fn offchain_worker(_block_number: T::BlockNumber) {
fn offchain_worker(_block_number: BlockNumberFor<T>) {
// check if the node has an account available, the offchain worker can't submit
// transactions without it
let signer = Signer::<T, T::AuthorityId>::any_account();
Expand Down
30 changes: 15 additions & 15 deletions pallets/bitcoin-vaults/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,40 @@ use frame_system::EnsureRoot;
use pallet_balances;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT summary of 79c45d - d9b909:

  • Added use sp_runtime::BuildStorage
  • Changed UncheckedExtrinsic to TestXt
  • Added type RuntimeEvent = RuntimeEvent and type Nonce = u64 to pallet_balances::Config
  • Changed type Index = u64 and type BlockNumber = u64 to type Nonce = u64 in frame_system::Config
  • Changed type Header = Header to type Block = Block in frame_system::Config
  • Added type RuntimeHoldReason = (), type FreezeIdentifier = (), type MaxHolds = () and type MaxFreezes = () to pallet_balances::Config
  • Added let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

use sp_core::H256;
//use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore};
use sp_runtime::BuildStorage;
use sp_runtime::{
testing::{Header, TestXt},
testing::TestXt,
traits::{BlakeTwo256, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify},
//RuntimeAppPublic,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
//use sp_runtime::generic::SignedPayload;
use sp_core::sr25519::Signature;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
BitcoinVaults: pallet_bitcoin_vaults::{Pallet, Call, Storage, Event<T>, ValidateUnsigned},
Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},
}
);

impl pallet_balances::Config for Test {
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type Balance = u64;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type WeightInfo = ();
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type MaxHolds = ();
type MaxFreezes = ();
}

parameter_types! {
Expand Down Expand Up @@ -106,14 +107,13 @@ impl frame_system::Config for Test {
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
type Hashing = BlakeTwo256;
type AccountId = sp_core::sr25519::Public;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
Expand All @@ -134,7 +134,7 @@ pub fn test_pub(n: u8) -> sp_core::sr25519::Public {

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(test_pub(1), 10000), (test_pub(2), 1000), (test_pub(3), 1000)],
}
Expand Down
22 changes: 8 additions & 14 deletions pallets/confidential-docs/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
use crate as pallet_confidential_docs;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT summary of 0cd5c6 - ab7e11:

  • Imported construct_runtime from frame_support
  • Changed the type of UncheckedExtrinsic to MockUncheckedExtrinsic
  • Changed the type of Block to MockBlock
  • Added BuildStorage to sp_runtime
  • Changed the type of Index and BlockNumber to u64
  • Changed the type of Header to Block
  • Added Nonce to frame_system::Config
  • Changed the type of GenesisConfig in frame_system::GenesisConfig to Test
  • Added build_storage to frame_system::GenesisConfig

use frame_support::parameter_types;
use frame_support::{construct_runtime, parameter_types};
use frame_system as system;
use frame_system::EnsureRoot;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
construct_runtime!(
pub enum Test
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
ConfidentialDocs: pallet_confidential_docs::{Pallet, Call, Storage, Event<T>},
}
);
Expand All @@ -35,13 +30,12 @@ impl system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand Down Expand Up @@ -85,7 +79,7 @@ impl pallet_confidential_docs::Config for Test {

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
let storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut ext: sp_io::TestExternalities = storage.into();
ext.execute_with(|| System::set_block_number(1));
ext
Expand Down
Loading