基于区块链的毕业设计EthAir Balloons – 乙炔气球

本文提供基于区块链的毕业设计国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,基于区块链的毕业设计EthAir Balloons – 乙炔气球 是一篇很好的国外资料

EthAir Balloons

EthAir Balloons - 乙炔气球

A strictly typed ORM library for Ethereum blockchain. It allows you to use Ethereum blockchain as a persistent storage in an organized and model-oriented way without 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 using ganache-cli .

Installation

npm i --save ethairballoons 

Setup

var ethAirBalloons = require('ethairballoons'); var path = require('path'); var savePath = path.resolve(__dirname + '/contracts');  var ethAirBalloonsProvider = ethAirBalloons('http://localhost:8545', savePath); //ethereum blockchain provider URL, path to save auto generated smart contracts  var Car = ethAirBalloonsProvider.createSchema({ 		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.

  1. the URL of the Ethereum blockchain provider that you want to use (in the example it is set to a local ganache-cli provider),
  2. 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 the createSchema() function and pass the schema details in JS object format. Of course you can (an it is advised) keep the schema definitions in separate .JSON files and then import them using the require() statement in the top of your file.

createSchema() returns a Schema object. In order to successfully initialize a Schema object, only one property of the schema definition must have primaryKey field set to true (as shown in the example above) and the type field must be set to one of the legal Solidity data types.

Functions of Schema object

Schema object 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 a Schema, 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:

Car.deploy(function (success, err) {     if (!err) {         console.log('Deployed successfully');     } });

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:

var newCarObject = {model:'Audi A4', engine: 'V8', wheels: 4}; Car.save(newCarObject, function (objectSaved, err) {    if (!err) {        console.log('object saved');    } });

find()

Returns all the records of our Schema. Example:

Car.find(function (allRecords, err) {    if (!err) {        console.log(allRecords);    } });

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:

Car.findById('Audi A4', function (record, err) {    if (!err) {        console.log(record);    } });

deleteById()

Deletes 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:

Car.deleteById('Audi A4', function (success, err) {    if (!err) {        console.log('object deleted successfully');    } });

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 updated record.

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:

var updatedCarObject = { engine: 'V9', wheels: 4 }; Car.updateById('Audi A4', updatedCarObject, function (updatedObject, err) {    if (!err) {        console.log('object updated successfully');    } });

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.

Tests

You can run tests by typing npm test in the root directory of the library.

License

EthAir Balloons are licensed under MIT license.

updated dependencies


EthAir气球

EthAir Balloons - 乙炔气球

以太坊eth区块链blockchain的严格类型ORM库。它允许您使用以太坊eth区块链blockchain作为一个有组织的、面向模型的持久存储,而无需编写定制的复杂智能合约。

注意:由于交易费用可能很高,强烈建议仅在私有以太坊eth区块链blockchain中或在本地使用ganache cli部署EthAir气球模型。

安装

npm i --save ethairballoons 

架构对象的函数要使用的区块链blockchain提供程序(在本例中设置为本地ganache cli提供程序),
  • 要保存模型自动生成的智能合约的路径。在
  • var ethAirBalloons = require('ethairballoons'); var path = require('path'); var savePath = path.resolve(__dirname + '/contracts');  var ethAirBalloonsProvider = ethAirBalloons('http://localhost:8545', savePath); //ethereum blockchain provider URL, path to save auto generated smart contracts  var Car = ethAirBalloonsProvider.createSchema({ 		name: "Car", 		contractName: "carsContract", 		properties: [ 		    { 		        name: "model", 				type: "bytes32", 				primaryKey: true 			}, 			{ 			    name: "engine", 			    type: "bytes32", 			}, 			{   name: "cylinders", 				type: "uint" 			} 		] 	});

    如您所见,只需设置2个参数,就可以非常容易地创建一个新的etharbalons提供程序(第3行)。

    1. 要保存模型自动生成的智能合约的路径。在
    2. the path where you want to save the automatically generated smart contracts of your models.

    创建提供程序后,可以使用createSchema()函数创建新的数据架构,并以JS对象格式传递架构详细信息。当然,您可以(建议这样做)将模式定义保存在单独的.JSON文件中,然后使用文件顶部的require()语句导入它们。

    createSchema()返回架构对象。要成功地在Schema中设置一个合法的字段类型(Solidity),必须在Schema中设置一个合法的字段类型(Solidity),才能成功地将primaryKey的类型设置为true。

    Functions of Schema object

    Schema对象实现执行CRUD操作所需的所有函数。由于所有区块链blockchain都具有异步特性,库中的所有函数都返回回调函数。初始化模式后,可以调用以下函数:

    deploy()

    这是必须调用的第一个函数,以便将模型设置为“启动并运行”。此函数生成模型的solidity智能合约,并将其部署到您在第一步中设置的基于以太坊eth区块链blockchain中。它返回一个布尔值,指示部署是否成功;如果部署成功,则返回一个未定义的错误对象。部署完成后,您可以调用其他函数。

    示例:

    Car.deploy(function (success, err) {     if (!err) {         console.log('Deployed successfully');     } });

    save()

    区块链blockchain中保存新记录。请确保在要保存的对象中设置主键字段,否则将返回错误。它返回保存的对象和一个错误对象,如果成功保存对象,则该对象将未定义。

    示例:

    var newCarObject = {model:'Audi A4', engine: 'V8', wheels: 4}; Car.save(newCarObject, function (objectSaved, err) {    if (!err) {        console.log('object saved');    } });

    find()

    返回模式的所有记录。示例:

    Car.find(function (allRecords, err) {    if (!err) {        console.log(allRecords);    } });

    findById()

    返回记录,如果存在,则返回具有特定主键值的记录。否则,它将返回一个错误对象,指出“具有此id的记录不存在”。

    示例:

    Car.findById('Audi A4', function (record, err) {    if (!err) {        console.log(record);    } });

    deleteById()

    删除具有特定主键值的记录(如果存在)。否则,它将返回一个错误对象,指出“具有此id的记录不存在”。

    示例:

    Car.deleteById('Audi A4', function (success, err) {    if (!err) {        console.log('object deleted successfully');    } });

    updateById()

    使用特定的主键值(如果存在)更新记录。否则,它将返回一个错误对象,指出“具有此id的记录不存在”。它返回更新的记录。

    第一个参数是要更新的记录的主键值。第二个参数是更新的对象。注意,与save()函数相反,没有必要设置主键字段,如果这样做,它将不会被更新。如果要将存储的记录重新分配给其他id,则必须先将其删除,然后用不同的主键值保存新的记录。

    示例:

    var updatedCarObject = { engine: 'V9', wheels: 4 }; Car.updateById('Audi A4', updatedCarObject, function (updatedObject, err) {    if (!err) {        console.log('object updated successfully');    } });

    setAccount(account)

    使用此函数,您可以显式设置要用于模型的ETH帐户。如果未设置,则默认情况下将帐户设置为提供程序的第一个帐户。

    Tests

    您可以通过在库的根目录中键入npm test来运行测试。

    License

    EthAir气球是根据麻省理工学院的许可证授权的。

    updated dependencies

    部分转自网络,侵权联系删除区块链源码网

    www.interchains.cc

    https://www.interchains.cc/19353.html

    区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
    区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » 基于区块链的毕业设计EthAir Balloons – 乙炔气球

    提供最优质的资源集合

    立即查看 了解详情