Skip to content

Commit

Permalink
Add storage paid and storage used (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Jul 7, 2022
1 parent 375eab7 commit 82fdacf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/api/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ export class NodeRPC {
.then(this.getObject)
}

getStoragePaidUsedByContract(network, contract, level = 'head') {
return this.getApi(network).get(`chains/main/blocks/${level}/context/raw/json/contracts/index/${contract}/paid_bytes`)
.then((res) => {
if (res.status != 200) {
throw new RequestFailedError(res);
}
return res.data;
})
}

getStorageUsedBytesByContract(network, contract, level = 'head') {
return this.getApi(network).get(`chains/main/blocks/${level}/context/raw/json/contracts/index/${contract}/used_bytes`)
.then((res) => {
if (res.status != 200) {
throw new RequestFailedError(res);
}
return res.data;
})
}

getObject(response) {
if (response.status != 200) {
throw new RequestFailedError(response);
Expand Down
2 changes: 1 addition & 1 deletion src/views/big_map/BigMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<v-list-item-content>
<v-list-item-subtitle class="overline">Total size</v-list-item-subtitle>
<v-list-item-title class="body-2">
<span>{{ totalBytes }} bytes</span>
<span>{{ parseInt(totalBytes).toLocaleString('en-US') }} bytes</span>
</v-list-item-title>
</v-list-item-content>
</v-list-item>
Expand Down
41 changes: 40 additions & 1 deletion src/views/contract/OperationsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@
:alias="contract.delegate_alias"
gutters
/>
<v-list-item v-if="usedBytes">
<v-list-item-content>
<v-list-item-subtitle class="overline">Storage used</v-list-item-subtitle>
<v-list-item-title class="body-2">
<span>{{ parseInt(usedBytes).toLocaleString('en-US') }} bytes</span>
</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item v-if="paidUsed">
<v-list-item-content>
<v-list-item-subtitle class="overline"
>Storage paid</v-list-item-subtitle
>
<v-list-item-title class="body-2">
<span>{{ parseInt(paidUsed).toLocaleString('en-US') }} bytes</span>
</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-col>
</v-row>
Expand Down Expand Up @@ -239,10 +257,15 @@ export default {
datesModal: false,
entrypoints: [],
availableEntrypoints: [],
operationsChannelName: null
operationsChannelName: null,
usedBytes: null,
paidUsed: null
}),
created() {
this.init();
this.getUsedBytes();
this.getPaidUsed();
},
computed: {
loading() {
Expand Down Expand Up @@ -311,6 +334,22 @@ export default {
}
return 0;
},
async getUsedBytes() {
this.usedBytes = await this.rpc.getStorageUsedBytesByContract(this.network, this.address)
.catch(err => {
console.log(err);
return null;
})
},
async getPaidUsed() {
this.paidUsed = await this.rpc.getStoragePaidUsedByContract(this.network, this.address)
.catch(err => {
console.log(err);
return null;
})
},
getTimestamps() {
let timestamps = this.dates.map((d) => dayjs(d).unix() * 1000).sort();
if (timestamps.length === 2) {
Expand Down

0 comments on commit 82fdacf

Please sign in to comment.