Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new generic service-consumer contract for pallet-smart-contract #495

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
2ec5aad
FEAT: moved contract billing to offchain worker #269
brandonpille Oct 3, 2022
fba68f7
FEAT: fixing tests #269
brandonpille Oct 3, 2022
5ed07fe
FEAT: modified pallet-smart-contract tests #269
brandonpille Aug 3, 2022
0d097f9
FEAT: Move registering extensions to offchainify function #269
brandonpille Aug 18, 2022
30640b9
wip
DylanVerstraete Aug 3, 2022
31a7e94
FEAT: fixed failing test #269
brandonpille Aug 3, 2022
452298c
FEAT: fixed all tests #269
brandonpille Aug 5, 2022
113fff3
FEAT:wrote our own TransactionPool mock that allows you to tell what …
brandonpille Aug 11, 2022
50b98b6
FEAT:rewrote some tests + inline documentation + better mocking #269
brandonpille Aug 12, 2022
25a44dc
FEAT: removed unused imports #269
brandonpille Aug 12, 2022
8146d20
FEAT: fixed a small mistake + commented the tests #269
brandonpille Aug 17, 2022
b29d5c2
FEAT: fixed merge conflicts #269
brandonpille Aug 18, 2022
b751c1e
FEAT: fixed transaction pool error handeling behavior #269
brandonpille Aug 18, 2022
ed4de4a
FEAT: cleaning up code #269
brandonpille Aug 19, 2022
c642031
FEAT: last log improvement #269
brandonpille Aug 19, 2022
99c59e6
chore: extend scripts
DylanVerstraete Aug 25, 2022
f0f7583
FEAT: remove duplicates before reinserting for next block #269
brandonpille Sep 5, 2022
25a1804
FEAT: more proper way to avoid dupplicates #269
brandonpille Sep 5, 2022
461bcea
FEAT: fixed tests #269
brandonpille Sep 5, 2022
15c0907
FEAT: debug logging when amount is 0 #269
brandonpille Sep 5, 2022
970d10f
FEAT: implementation unauthorized billing #269
brandonpille Sep 6, 2022
e7815f0
FEAT: check if signer can sign before sending transaction #269
brandonpille Sep 7, 2022
41bd1a1
Revert "FEAT: implementation unauthorized billing #269"
DylanVerstraete Sep 20, 2022
35b1524
chore: reinstate one line of code
DylanVerstraete Sep 20, 2022
2ce047a
feat: review comments #269
brandonpille Oct 3, 2022
b63dfac
feat: fixed issue due to rebase #269
brandonpille Oct 3, 2022
668ef5f
feat: rework contract billing storage (#477)
DylanVerstraete Oct 12, 2022
e990ad9
chore: cleanup
DylanVerstraete Oct 12, 2022
052d7a1
chore: update chart
DylanVerstraete Oct 12, 2022
6f690d1
chore: merge development
DylanVerstraete Oct 12, 2022
880185c
chore: add adr for changes
DylanVerstraete Oct 12, 2022
5714a03
wip
DylanVerstraete Oct 5, 2022
ee92733
more wip
DylanVerstraete Oct 6, 2022
d5160a5
chore: some cleaning
DylanVerstraete Oct 7, 2022
fc5b015
chore: test artifact upload
DylanVerstraete Oct 7, 2022
53836f7
chore: fix yaml
DylanVerstraete Oct 7, 2022
3be2d5f
chore: fix yaml again
DylanVerstraete Oct 7, 2022
7b13f78
chore: upload artifact if job failed
DylanVerstraete Oct 7, 2022
4caf435
chore: wait x blocks after cancel
DylanVerstraete Oct 10, 2022
4320ee0
chore: move get index to function
DylanVerstraete Oct 10, 2022
a5cce78
chore: refactor
DylanVerstraete Oct 10, 2022
0321751
fix: billing
DylanVerstraete Oct 10, 2022
74bfc0d
feat: initial commit #473
brandonpille Oct 4, 2022
b621682
feat: added events and extrinsic for creating deployment contract #47…
brandonpille Oct 5, 2022
1d916a3
feat: major implementation for feature #473
brandonpille Oct 7, 2022
62c2027
feat: made update_node_contract deprecated #473
brandonpille Oct 7, 2022
8a44388
feat: fixed tests #473
brandonpille Oct 7, 2022
78731ca
feat: fixed integration tests #473
brandonpille Oct 7, 2022
f3b6277
feat: lets try fixing int tests #473
brandonpille Oct 7, 2022
a38b72d
feat: modified event name #473
brandonpille Oct 10, 2022
690775f
feat: added extra tests #473
brandonpille Oct 10, 2022
77f9cb8
feat: extra tests and cleanup code #473
brandonpille Oct 11, 2022
0a9e165
feat: fixed mergeconflicts #473
brandonpille Oct 11, 2022
611d6ff
feat: implementation of contract policy (aka grouping of contracts) #…
brandonpille Oct 11, 2022
4aad91f
feat: fixed merge conflicts #473
brandonpille Oct 12, 2022
aceb176
feat: fixed integration tests #473
brandonpille Oct 12, 2022
7e536d1
feat: implementation done and code can be build
brandonpille Oct 18, 2022
8cbd6a9
fixed most tests
brandonpille Oct 18, 2022
e22f18c
fixed all tests
brandonpille Oct 18, 2022
bedc58c
improved tests
brandonpille Oct 20, 2022
d45fe28
fixed unit tests
brandonpille Oct 21, 2022
793e67c
tests on grouping
brandonpille Oct 21, 2022
b0aa44a
added unit tests on public config filtering
brandonpille Oct 24, 2022
57b62bb
fixed integration tests
brandonpille Oct 25, 2022
8758e06
fixed integration tests
brandonpille Oct 25, 2022
75bb96e
fixed unit tests
brandonpille Oct 25, 2022
251f387
feat: add new service contract type
renauter Oct 26, 2022
f62819d
feat: evolving on service contract approval flow
renauter Oct 27, 2022
0ea8829
test: add service contract basic tests and samll improvements
renauter Oct 28, 2022
986304a
feat: contract approval complete cycle and test improvements
renauter Nov 3, 2022
189f0e1
feat: wip service send bill report
renauter Nov 7, 2022
d5ae226
test: some updates after changing base branch
renauter Nov 7, 2022
01e02a0
test: typo correction
renauter Nov 7, 2022
1e46023
feat service contract billing extrinsic
renauter Nov 8, 2022
a9af8f7
test: fix after changing base branch
renauter Nov 8, 2022
98dbab4
feat: update cost of service contract regarding bill
renauter Nov 8, 2022
d9d2ca2
feat: update time strategy for billing
renauter Nov 8, 2022
bbd3ce8
feat: wip rework service billing
renauter Nov 16, 2022
2b0088e
feat: simplifying service contract billing
renauter Nov 16, 2022
48e870e
feat: simplifying service contract billing (2)
renauter Nov 16, 2022
1234563
feat: handle service contract cancelation
renauter Nov 16, 2022
2488082
Merge branch 'feature/473-implement-power-management-and-capacity-pla…
renauter Nov 17, 2022
36a44f4
fix: resolve conflicts after merge
renauter Nov 17, 2022
e64bb5a
Merge branch 'feature/473-implement-power-management-and-capacity-pla…
renauter Nov 17, 2022
7771c1d
fix: resolve conflicts after merge
renauter Nov 17, 2022
089e5f5
test: service contract cancelation and billing
renauter Nov 18, 2022
4216733
test: refine service contract testing (1)
renauter Nov 18, 2022
c0a8263
test: refine service contract testing (2)
renauter Nov 18, 2022
c769369
test: refine service contract testing (3)
renauter Nov 18, 2022
b7816c7
fix out of funds test and do some cleanup
renauter Nov 18, 2022
aa5d7ef
Merge branch 'feature/473-implement-power-management-and-capacity-pla…
renauter Nov 21, 2022
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
32 changes: 31 additions & 1 deletion substrate-node/pallets/pallet-smart-contract/src/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::pallet;
use crate::pallet::BalanceOf;
use crate::pallet::Error;
use crate::types;
use crate::types::{Contract, ContractBillingInformation};
use crate::types::{Contract, ContractBillingInformation, ServiceContract, ServiceContractBill};
use crate::Config;
use frame_support::dispatch::DispatchErrorWithPostInfo;
use pallet_tfgrid::types as pallet_tfgrid_types;
Expand Down Expand Up @@ -88,6 +88,36 @@ impl<T: Config> Contract<T> {
}
}

impl<T: Config> ServiceContract<T> {
pub fn calculate_bill_cost_tft(
&self,
service_bill: ServiceContractBill,
) -> Result<BalanceOf<T>, DispatchErrorWithPostInfo> {
// Calculate the cost in mUSD for service contract bill
let total_cost = self.calculate_bill_cost(service_bill);

if total_cost == 0 {
return Ok(BalanceOf::<T>::saturated_from(0 as u128));
}

// Calculate the cost in TFT for service contract
let total_cost_tft_64 = calculate_cost_in_tft_from_musd::<T>(total_cost)?;

// convert to balance object
let amount_due: BalanceOf<T> = BalanceOf::<T>::saturated_from(total_cost_tft_64);

return Ok(amount_due);
}

pub fn calculate_bill_cost(&self, service_bill: ServiceContractBill) -> u64 {
// bill user for service usage for elpased usage (window) in seconds
let contract_cost = U64F64::from_num(self.base_fee)
* U64F64::from_num(service_bill.window) / 3600
+ U64F64::from_num(service_bill.variable_amount);
contract_cost.round().to_num::<u64>()
}
}

// Calculates the total cost of a node contract.
pub fn calculate_resources_cost<T: Config>(
resources: &Resources,
Expand Down
Loading