Package: ethairballoons
EthAir BalloonsA strictly typed ORM library for Ethereum blockchain.
It allows you to use Ethereum blockchain as a persistent storage in an organized and model-oriented waywithout writing custom complex Smart contracts.Note:
As transaction fees may be huge, it is strongly advised to only deploy EthAir Balloons models in private Ethereum blockchains or locally usingganache.Installationpip install ethairballoonsSetupfromethairballoonsimportethairBalloons# frist parameter is the IP of the Ethereum network we want to store data# seconda parameter is the path to save to smart contractprovider=ethairBalloons('127.0.0.1','../')mySchema=provider.createSchema(modelDefinition={'name':"Car",'contractName':"carsContract",'properties':[{'name':"model",'type':"bytes32",'primaryKey':True},{'name':"engine",'type':"bytes32",},{'name':"cylinders",'type':"uint"}]})As you can see you can very easily create a new ethAirBaloons provider (line 3) by setting only 2 arguments.the URL of the Ethereum blockchain provider that you want to use
(in the example it is set to a localganacheprovider),the path where you want to save the automatically generated smart contracts of your models.After you create the provider you can create new data schemas using thecreateSchema()function and pass the schema details in dictionary format.
Of course you can (an it is advised) keep the schema definitions in separate .JSON files and then import them using theimport jsonand thenjson.load()statements.createSchema()returns aSchemaobject.
In order to successfully initialize aSchemaobject,only oneproperty
of the schema definition must haveprimaryKeyfield set toTrue(as shown in the example above)
and thetypefield must be set to one of the legalSolidity data types.Functions ofSchemaobjectSchemaobject implements all the functions needed to perform CRUD operations.
As all blockchains have an asynchronous nature, all functions in the library return a callback function.
After you initialize aSchema, you can call the following functions:deploy()It is the fist function that you must call in order to set your model up "up and running".
This function generates the solidity Smart contract of your model and it deploys
it in the Ethereum based blockchain that you have set in the first step.
It returns a boolean indicating if the deploy is successfull and an error object that will be undefined if the deploy is successfull.
After deploy completes you can call the other functions.Example:mySchema.deploy()save()Saves a new record in th blockchain. Make sure to set the primary key field in the object you want to save, otherwise an error will be returned.
It returns the saved object and an error object that will be undefined if the object is saved successfully.Example:save_receipt=mySchema.save({'model':'A4','engine':'V8','cylinders':'8'})find()Returns all the records of our Schema.
Example:all_records=mySchema.find()findById()Returns the record with a specific primary key value if exists.
Otherwise it will return an error object mentioning that 'record with this id does not exist'.Example:record_by_id=mySchema.findById('A4')deleteById()Deletes the record with a specific primary key value if exists. It returnsTrueif the operation completed successfully.
Otherwise it will returnFalse.Example:delete_receipt=mySchema.deleteById('A4')updateById()Updates the record with a specific primary key value if exists.
Otherwise it will return an error object mentioning that 'record with this id does not exist'.
It returns the True or False that indicates if the operation completed successfullt or not.The first parameter is the primary key value of the record we want to update.
The second parameter is the updated object.
Note that is contrary with save() function it is not necessary to set the primary key field and if you do so, it will NOT be updated.
If you want to reassign a stored record to a different id you must first delete it and then save a new one with the different primary key value.Example:update_receipt=mySchema.updateById('A4',{'model':'A4','engine':'V18','cylinders':'18'})setAccount(account)With this function you can explicitly set the ETH account that you want to use for the model.
If not set, account is set by default to the first account of the provider.JavaScript versionEthairBalloons is also available for JavaScript inthis GitHub repository.You can also install it vianpm install ethairballoonsLicenseEthAir Balloons are licensed under MIT license.