Terry  Tremblay

Terry Tremblay

1598349360

Dynamic Value Arrays in Solidity

Background

During the development and testing of Datona Labs’ Solidity smart data access contract (S-DAC) templates, we often need to handle data with a small but unknown number of items, such as user IDs. Ideally, these are stored in small dynamic arrays of small values.

In the examples for this article, we investigate whether using dynamic value arrays helps us to do that more efficiently than using reference arrays or similar solutions in Solidity.


Discussion

Where we have data comprising a known small number of small numbers, we can employ a value array in Solidity, as per the article “Value Arrays in Solidity” by the author, in which we provide and measure Solidity value arrays. We concluded, amongst other things, that we can reduce my storage space and gas consumption using value arrays in many circumstances.

This conclusion was reached because Solidity runs on the Ethereum Virtual Machine (EVM) which has a very large machine word of 256bits (32bytes). This feature, combined with high gas consumption for reference array handling, encourages us to consider using value arrays.

However, if we are providing our own libraries for fixed value array manipulation, let us determine whether it is feasible to provide dynamic value arrays as well.

Let us compare dynamic value arrays with fixed value arrays and Solidity’s own fixed and dynamic arrays.

We shall also compare a struct containing a length and a fixed array, as well as a struct containing a value array.


Possible Dynamic Value Arrays

In Solidity, it is only possible to have dynamic storage arrays. Memory arrays have a fixed size and are not permitted to use push() in order to append additional elements.

Since we are providing our own code for dynamic value arrays in Solidity libraries, we can also provide push()(and pop()) to be used on both storage and memory arrays.

Dynamic value arrays will need to record and manipulate the current length of the array. In the following code, we have chosen to store the length in the top bits of the 256bit-, 32byte-machine word value.

Dynamic value arrays

These are dynamic value arrays that match some of the Solidity available types:

Dynamic Value Arrays

Type           Type Name   Description
uint128[](1)   uint128d1   one 128bit element value
uint64[](3)    uint64d3    three 64bit element values
uint32[](7)    uint32d7    seven 32bit element values
uint16[](15)   uint16d15   fifteen 16bit element values
uint8[](31)    uint8d31    thirty-one 8bit element values

We propose the Type Name as shown above, which is used throughout this article, but you may find a preferable naming convention.

We will be looking at uint8d31 in more detail, below.

More dynamic value arrays

Obviously, there more possible value arrays. Assuming that we are reserving the top bits of the 256bit value to hold the maximum dynamic array length, the number of bits in the X value multiplied by the number of Y elements must be less than or equal to 256 minus enough bits to hold the array length, L:

More Dynamic Value Arrays

Type           Type Name  Len  Description
uintX[](Y)     uintXdY     L   X * Y <= 256 - L
uint255[](1)   uint255d1   1   one 248bit element value
uint126[](2)   uint126a2   2   two 124bit element values
uint84[](3)    uint84d3    2   three 82bit element values
uint63[](4)    uint63d4    3   four 62bit element values
uint50[](5)    uint50d5    3   five 51bit element values
uint42[](6)    uint42d6    3   six 42bit element values
uint36[](7)    uint36d7    3   seven 36bit element values
uint31[](8)    uint31d8    4   eight 31bit element values
uint28[](9)    uint28d9    4   nine 28bit element values
uint25[](10)   uint25d10   4   ten 25bit element values
uint22[](11)   uint22d11   4   eleven 22bit element values
uint21[](12)   uint21d12   4   twelve 21bit element values
uint19[](13)   uint19d13   4   thirteen 19bit element values
uint18[](14)   uint18d14   4   fourteen 18bit element values
uint16[](15)   uint16d15   4   as above
uint15[](16)   uint15d16   5   sixteen 15bit element values
uint14[](17)   uint14d17   5   seventeen 14bit element values
uint13[](19)   uint13d19   5   nineteen 13bit element values
uint12[](20)   uint12d20   5   twenty 12bit element values
uint11[](22)   uint11d22   5   twenty-two 11bit element values
uint10[](25)   uint10d25   5   twenty-five 10bit element values
uint9[](27)    uint9d27    5   twenty-seven 9bit element values
uint8[](31)    uint8d31    5   as above
uint7[](35)    uint7d35    6   thirty-five 7bit element values
uint6[](41)    uint6d41    6   forty-one 6bit element values
uint5[](50)    uint5d50    6   fifty 5bit element values
uint4[](62)    uint4d62    6   sixty-two 4bit element values
uint3[](83)    uint3d83    7   eighty-three 3bit element values
uint2[](124)   uint2d124   7   one-hundred & twenty-four 2bit EVs
uint1[](248)   uint1d248   8   two-hundred & forty-eight 1bit EVs

The array type needed is project-specific. Additionally, multiple array types may be needed, for instance, uint8d31 for user IDs and uint5d50 for roles.

Note the uint1d248 value array. That allows us to efficiently encode up to 248 one-bit element values, which represent booleans, into one EVM word. Compare that with Solidity’s bool[248] which consumes 248 times as much space in memory and even eight times as much space in storage.

#ethereum #blockchain #solidity #smart-contracts #programming

What is GEEK

Buddha Community

Dynamic Value Arrays in Solidity

Bhakti Rane

1624531051

Alerts4Dynamics - Alerts / Notifications Management in Dynamics 365 CRM

Alerts4Dynamics is productivity app for Dynamics 365 CRM that helps to create, schedule, manage and track alerts. It helps to notify and pass relevant information to target audience right within Dynamics 365 CRM. These notifications can be created and displayed indefinitely or for a defined scheduled period. Notification button is available on all entities and can be accessed from anywhere in the CRM.
Features
• Create Announcement and Rule Based/Record Based alerts.
• Alerts can be sent as Pop-ups, Form Notifications or Email to target Dynamics 365 CRM users.
• Categorize alerts as Information, Warning or Critical.
• Track log of read/dismissed alerts by users.
• Define process start date from when the notifications will start getting created and process end date when creation of new notifications will stop. Also, add the display end date for notification.

https://www.inogic.com/product/productivity-apps/add-manage-schedule-notifications-alerts-4-dynamics-365-crm

#dynamics 365 pop-up alert #dynamics 365 email alerts #dynamics 365 bulk alerts #dynamics crm pop-up alert #dynamics 365 notifications #dynamics crm alert

Bhakti Rane

1625057623

Click2Undo - 1 Click App to restore Dynamics 365 CRM data to its last known state

Undo changes & restore records in Dynamics 365 CRM with a single click

Click2Undo is a productivity app that helps you to undo changes in the data in Dynamics 365 CRM with a single click. Be it the last change that you’d want to restore, or the changes that were done in the past which you would like to get back, Click2Undo can do it without any hassle. This provides a safety net within which users can conduct day-to-day activities without fear of losing data due to human or technical errors.
Click2Undo is available for Dynamics CRM 8.2 and above, Dataverse (Power Apps). It supports deployment models - On-Premises and Online.
Features
• Entity Support: Click2Undo provides support to all OOB as well as Custom Entities
• Undo Last Changes: Ability to restore the last changes done to a Dynamics 365 CRM record by clicking the Click2Undo button
• Undo Past Changes: Ability to undo past changes made to multiple fields on Dynamics 365 CRM records in one go using History button
• Undo Bulk Changes: Ability to undo changes on multiple records at one go.

#restore last state of dynamics 365 records #restoring deleted dynamics 365 records #recovering deleted dynamics 365 records #recover deleted dynamics crm records #dynamics 365 online recover deleted records #restore records dynamics crm

Fredy  Larson

Fredy Larson

1599278730

How to Build a Dynamic Array By Using a Static Array in Java

We all know about the basic data structure, which is** Array **pretty well. And in java they are static. It means we have to allocate memory for the array ahead of time. The memory will define the number of elements that the array can hold. But what if we have know idea about the exact number of elements that we are going to insert before hand. Then the best thing is to have a dynamic array.

A dynamic array automatically grows when we try to make an insertion and there is no space left for the new item. A simple dynamic array can be constructed, by using an array of fixed-size. The elements of the array are stored contiguously, for an instance, if it is an integer type array it will take 4 bytes of space per integer element. The remaining positions towards the end are reserved and unused. New elements can be added to the end of the array until the reserved space is fully utilized. If you still need to add up more elements even after that, the array needs to be resized which is a very expensive task. Usually it doubles its size.

Following is the Figure 1, where you can find the Array class, to model a dynamic behavior by using a static array in Java. Basic array operations are implemented below.

public class Array {

		private int[] items;
		private int count;

		public Array(int length) {

			items = new int[length];
		}

		public void print() {

			for(int i=0;i<count;i++) {
				System.out.println(items[i]);
			}
		}

		public void insert(int number) {

			//If an item is added to the end
			items[count]=number;
			count++;

			//If the array is full, resize it
			if(items.length == count) {

				int[] newItems = new int[count*2];

				for(int i=0;i<count;i++) {
					newItems[i]=items[i];
				}

				items=newItems;
			}

		}

		//Delete
		public void removeAt(int index) {

			if(index<0 || index>=count ) {
				throw new IllegalArgumentException();
			}	

			for(int i=index;i<count;i++) {
				items[i]=items[i+1];
			}

			count--;
		}

		//Search
		public int indexOf(int number) {

			for(int i=0;i<count;i++) {
				if(number == items[i]) {
					return i;
				}
			}

			return -1;

		}
	}

#dynamic-array #data-structures #java #arrays

Joseph  Murray

Joseph Murray

1623911281

How to Print an Array in Java

Introduction

Printing an array is a quick way to give us visibility on the values of the contents inside. Sometimes the array values are the desired output of the program.

In this article, we’ll take a look at how to print an array in Java using four different ways.

While the “best way” depends on what your program needs to do, we begin with the simplest method for printing and then show more verbose ways to do it.

#java #array #how to print an array in java #array in java #print an array in java #print

Bhakti Rane

1625057189

Auto Tax Calculator - Efficient & Effortless Automatic Tax Calculations

Auto Tax Calculator enables users to calculate tax automatically within Dynamics 365 for Sales. With this productivity app, there is no further need to calculate tax manually which increases accuracy and efficiency of users. Your taxes can be applied correctly the first time in order thereby, saving your time and effort during tax season.
Auto Tax Calculator is available for Dynamics 365 8.2 & above and Power Apps. It supports Dynamics 365 On-Premises & Online.
Features
• Automatic Tax Calculation: Calculate tax automatically for OOB entities – Opportunity, Quote, Order and Invoice
• Tax Schedules & Details: Create specific Tax Schedules and Tax Details to calculate taxes automatically
• AvaTax Integration: Seamless integration with AvaTax from Avalara
• Geolocational Tax Calculation: Calculate taxes as per the rules and regulations stated for specific geographical locations using AvaTax
https://www.inogic.com/product/productivity-apps/automated-tax-calculation-processing-dynamics-365-crm

#automatic tax calculations dynamics 365 #avalara integration dynamics crm #avalara integration dynamics 365 #tax calculation dynamics 365 #tax calculation dynamics crm #tax processing application dynamics crm