Skip to content

Commit

Permalink
Release 0.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jernejpregelj committed Nov 16, 2017
1 parent 4a0a509 commit b5137ac
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package-lock.json

# production
/build
dist

# misc
.DS_Store
Expand Down
2 changes: 2 additions & 0 deletions dist/browser/bigchaindb-orm.amd.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/browser/bigchaindb-orm.amd.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/browser/bigchaindb-orm.cjs.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/browser/bigchaindb-orm.cjs.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/browser/bigchaindb-orm.cjs2.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/browser/bigchaindb-orm.cjs2.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/browser/bigchaindb-orm.umd.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/browser/bigchaindb-orm.umd.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/browser/bigchaindb-orm.window.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/browser/bigchaindb-orm.window.min.js.map

Large diffs are not rendered by default.

180 changes: 180 additions & 0 deletions dist/node/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _bigchaindbDriver = require('bigchaindb-driver');

var driver = _interopRequireWildcard(_bigchaindbDriver);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// eslint-disable-line import/no-namespace

var Connection = function () {
function Connection(path) {
var headers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

_classCallCheck(this, Connection);

this.path = path;
this.headers = _extends({}, headers);
this.conn = new driver.Connection(path, headers);
}

_createClass(Connection, [{
key: 'getAssetId',
value: function getAssetId(tx) {
// eslint-disable-line class-methods-use-this
return tx.operation === 'CREATE' ? tx.id : tx.asset.id;
}
}, {
key: 'getTransaction',
value: function getTransaction(transactionId) {
return this.conn.getTransaction(transactionId);
}
}, {
key: 'listTransactions',
value: function listTransactions(assetId, operation) {
return this.conn.listTransactions(assetId, operation);
}
}, {
key: 'listOutputs',
value: function listOutputs(publicKey, spent) {
return this.conn.listOutputs(publicKey, spent);
}
}, {
key: 'getBlock',
value: function getBlock(blockId) {
return this.conn.getBlock(blockId);
}
}, {
key: 'listBlocks',
value: function listBlocks(transactionId) {
var _this = this;

return this.conn.listBlocks(transactionId).then(function (blockIds) {
return Promise.all(blockIds.map(function (blockId) {
return _this.conn.getBlock(blockId);
}));
});
}
}, {
key: 'listVotes',
value: function listVotes(blockId) {
return this.conn.listVotes(blockId);
}
}, {
key: 'searchAssets',
value: function searchAssets(text) {
return this.conn.searchAssets(text);
}
}, {
key: 'createTransaction',
value: function createTransaction(publicKey, privateKey, payload, metadata) {
var _this2 = this;

try {
// Create a transation
var tx = driver.Transaction.makeCreateTransaction(payload, metadata, [driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(publicKey))], publicKey);

// sign/fulfill the transaction
var txSigned = driver.Transaction.signTransaction(tx, privateKey);

// send it off to BigchainDB
return this.conn.postTransaction(txSigned).then(function () {
return _this2.conn.pollStatusAndFetchTransaction(txSigned.id);
}).then(function () {
return txSigned;
});
} catch (error) {
return Promise.reject(error);
}
}
}, {
key: 'transferTransaction',
value: function transferTransaction(tx, fromPublicKey, fromPrivateKey, toPublicKey, metadata) {
var _this3 = this;

try {
var txTransfer = driver.Transaction.makeTransferTransaction(tx, metadata, [driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(toPublicKey))], 0);

var txTransferSigned = driver.Transaction.signTransaction(txTransfer, fromPrivateKey);
// send it off to BigchainDB
return this.conn.postTransaction(txTransferSigned).then(function () {
return _this3.conn.pollStatusAndFetchTransaction(txTransferSigned.id);
}).then(function () {
return txTransferSigned;
});
} catch (error) {
return Promise.reject(error);
}
}
}, {
key: 'getSortedTransactions',
value: function getSortedTransactions(assetId) {
return this.conn.listTransactions(assetId).then(function (txList) {
if (txList.length <= 1) {
return txList;
}
var inputTransactions = [];
txList.forEach(function (tx) {
return tx.inputs.forEach(function (input) {
if (input.fulfills) {
inputTransactions.push(input.fulfills.transaction_id);
}
});
});
var unspents = txList.filter(function (tx) {
return inputTransactions.indexOf(tx.id) === -1;
});
if (unspents.length) {
var _ret = function () {
var tipTransaction = unspents[0];
var tipTransactionId = tipTransaction.inputs[0].fulfills.transaction_id;
var sortedTxList = [];
while (true) {
// eslint-disable-line no-constant-condition
sortedTxList.push(tipTransaction);
try {
tipTransactionId = tipTransaction.inputs[0].fulfills.transaction_id;
} catch (e) {
break;
}
if (!tipTransactionId) {
break;
}
tipTransaction = txList.filter(function (tx) {
return (// eslint-disable-line no-loop-func
tx.id === tipTransactionId
);
})[0];
}
return {
v: sortedTxList.reverse()
};
}();

if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
} else {
console.error('something went wrong while sorting transactions', txList, inputTransactions);
}
return txList;
});
}
}]);

return Connection;
}();

exports.default = Connection;
module.exports = exports['default'];
43 changes: 43 additions & 0 deletions dist/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _connection = require('./connection');

var _connection2 = _interopRequireDefault(_connection);

var _ormobject = require('./ormobject');

var _ormobject2 = _interopRequireDefault(_ormobject);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Orm = function () {
function Orm(connectionUrl, headers) {
_classCallCheck(this, Orm);

this.connection = new _connection2.default(connectionUrl, headers);
this.appId = '';
if (headers && headers.app_id) {
this.appId = headers.app_id;
}
}

_createClass(Orm, [{
key: 'define',
value: function define(modelName, modelSchema) {
this[modelName] = new _ormobject2.default(modelName, modelSchema, this.connection, this.appId);
}
}]);

return Orm;
}();

exports.default = Orm;
module.exports = exports['default'];
113 changes: 113 additions & 0 deletions dist/node/ormobject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _v = require('uuid/v4');

var _v2 = _interopRequireDefault(_v);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// The likelihood to generate a vanity address that is 11 times "Burn" is extremely low:
// - https://en.bitcoin.it/wiki/Vanitygen#Use_of_vanitygen_to_try_to_attack_addresses
var BURN_ADDRESS = 'BurnBurnBurnBurnBurnBurnBurnBurnBurnBurnBurn';

var OrmObject = function () {
function OrmObject(modelName, modelSchema, connection) {
var appId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
var transactionList = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];

_classCallCheck(this, OrmObject);

this._name = modelName;
this._schema = modelSchema;
this._connection = connection;
this._appId = appId;
if (transactionList.length) {
this.transactionHistory = transactionList;
this.id = transactionList[0].asset.data[this._appId + '-' + this._name].id;
this.data = _extends.apply(undefined, [{}].concat(_toConsumableArray(transactionList.map(function (tx) {
return tx.metadata;
}))));
}
}

_createClass(OrmObject, [{
key: 'retrieve',
value: function retrieve(input) {
var _this = this;

var query = input || '"' + this._appId + '-' + this._name + '"';
return this._connection.searchAssets('"' + query + '"').then(function (assets) {
return Promise.all(assets.map(function (asset) {
return _this._connection.getSortedTransactions(asset.id).then(function (txList) {
return new OrmObject(_this._name, _this._schema, _this._connection, _this._appId, txList);
});
}));
});
}
}, {
key: 'create',
value: function create(inputs) {
var _this2 = this;

if (inputs === undefined) {
console.error('inputs missing');
}
var assetPayload = {};
assetPayload[this._appId + '-' + this._name] = {
'schema': this._schema,
'id': 'id:' + this._appId + ':' + (0, _v2.default)()
};
return this._connection.createTransaction(inputs.keypair.publicKey, inputs.keypair.privateKey, assetPayload, inputs.data).then(function (tx) {
return Promise.resolve(_this2._connection.getSortedTransactions(tx.id).then(function (txList) {
return new OrmObject(_this2._name, _this2._schema, _this2._connection, _this2._appId, txList);
}));
});
}
}, {
key: 'append',
value: function append(inputs) {
var _this3 = this;

if (inputs === undefined) {
console.error('inputs missing');
}
return this._connection.transferTransaction(this.transactionHistory[this.transactionHistory.length - 1], inputs.keypair.publicKey, inputs.keypair.privateKey, inputs.toPublicKey, inputs.data).then(function () {
return Promise.resolve(_this3._connection.getSortedTransactions(_this3.transactionHistory[0].id).then(function (txList) {
return new OrmObject(_this3._name, _this3._schema, _this3._connection, _this3._appId, txList);
}));
});
}
}, {
key: 'burn',
value: function burn(inputs) {
var _this4 = this;

if (inputs === undefined) {
console.error('inputs missing');
}

return this._connection.transferTransaction(this.transactionHistory[this.transactionHistory.length - 1], inputs.keypair.publicKey, inputs.keypair.privateKey, BURN_ADDRESS, { status: 'BURNED' }).then(function () {
return Promise.resolve(_this4._connection.getSortedTransactions(_this4.transactionHistory[0].id).then(function (txList) {
return new OrmObject(_this4._name, _this4._schema, _this4._connection, _this4._appId, txList);
}));
});
}
}]);

return OrmObject;
}();

exports.default = OrmObject;
module.exports = exports['default'];
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bigchaindb-orm",
"version": "0.1.7",
"version": "0.1.8",
"description": "A CRAB-based ORM for BigchainDB",
"homepage": "https://www.bigchaindb.com/",
"bugs": "https://github.com/bigchaindb/js-driver-orm/issues",
Expand Down Expand Up @@ -30,15 +30,15 @@
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015-no-commonjs": "^0.0.2",
"babel-runtime": "^6.26.0",
"cross-env": "^5.0.3",
"eslint": "^4.3.0",
"cross-env": "^5.1.1",
"eslint": "^4.11.0",
"eslint-config-ascribe": "^3.0.4",
"eslint-plugin-import": "^2.7.0",
"nyc": "^11.1.0",
"eslint-plugin-import": "^2.8.0",
"nyc": "^11.3.0",
"release-it": "^3.0.0",
"rimraf": "^2.5.4",
"rimraf": "^2.6.2",
"sinon": "^4.0.0",
"webpack": "^3.5.2"
"webpack": "^3.8.1"
},
"scripts": {
"lint": "./node_modules/eslint/bin/eslint.js ./src",
Expand All @@ -49,10 +49,10 @@
"clean": "rimraf dist/bundle dist/node",
"test": "npm run lint && nyc ava test/ && npm run thanks && npm run report-coverage",
"thanks": "cowsay Hi, thanks for your interest in BigchainDB. We appreciate your contribution!",
"prepublishOnly": "npm update && npm run build",
"release": "./node_modules/release-it/bin/release.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"release-minor": "./node_modules/release-it/bin/release.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"release-major": "./node_modules/release-it/bin/release.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"prepublishOnly": "npm run build",
"release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"release-minor": "./node_modules/release-it/bin/release-it.js minor --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"release-major": "./node_modules/release-it/bin/release-it.js major --src.tagName='v%s' --github.release --npm.publish --non-interactive",
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov"
},
"keywords": [
Expand Down

0 comments on commit b5137ac

Please sign in to comment.