tripio
Version:
Tripio SDK for JavaScript
1,780 lines (1,671 loc) • 94.7 kB
JavaScript
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var Web3 = _interopDefault(require('web3'));
var bs58 = _interopDefault(require('bs58'));
var buffer = require('buffer');
var VABI = [{
"constant": false,
"inputs": [{
"name": "_name",
"type": "string"
}, {
"name": "_ipfs",
"type": "bytes32"
}],
"name": "createRatePlan",
"outputs": [{
"name": "",
"type": "uint256"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}, {
"name": "_rpid",
"type": "uint256"
}, {
"name": "_date",
"type": "uint256"
}, {
"name": "_token",
"type": "uint256"
}],
"name": "priceOfDate",
"outputs": [{
"name": "_inventory",
"type": "uint16"
}, {
"name": "_price",
"type": "uint256"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}, {
"name": "_rpid",
"type": "uint256"
}, {
"name": "_dates",
"type": "uint256[]"
}, {
"name": "_token",
"type": "uint256"
}],
"name": "pricesAndInventoriesOfDate",
"outputs": [{
"name": "",
"type": "uint256[]"
}, {
"name": "",
"type": "uint16[]"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_rpid",
"type": "uint256"
}, {
"name": "_name",
"type": "string"
}, {
"name": "_ipfs",
"type": "bytes32"
}],
"name": "modifyRatePlan",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}, {
"name": "_rpid",
"type": "uint256"
}],
"name": "ratePlanOfVendor",
"outputs": [{
"name": "_name",
"type": "string"
}, {
"name": "_timestamp",
"type": "uint256"
}, {
"name": "_ipfs",
"type": "bytes32"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}, {
"name": "_from",
"type": "uint256"
}, {
"name": "_limit",
"type": "uint256"
}],
"name": "ratePlansOfVendor",
"outputs": [{
"name": "",
"type": "uint256[]"
}, {
"name": "",
"type": "uint256"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_rpid",
"type": "uint256"
}, {
"name": "_tokens",
"type": "uint256[]"
}, {
"name": "_prices",
"type": "uint256[]"
}, {
"name": "_inventory",
"type": "uint16"
}],
"name": "updateBasePrice",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}, {
"name": "_rpid",
"type": "uint256"
}, {
"name": "_dates",
"type": "uint256[]"
}, {
"name": "_token",
"type": "uint256"
}],
"name": "pricesOfDate",
"outputs": [{
"name": "",
"type": "uint256[]"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": false,
"inputs": [],
"name": "acceptOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [{
"name": "",
"type": "address"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_rpid",
"type": "uint256"
}, {
"name": "_dates",
"type": "uint256[]"
}, {
"name": "_inventory",
"type": "uint16"
}, {
"name": "_tokens",
"type": "uint256[]"
}, {
"name": "_prices",
"type": "uint256[]"
}],
"name": "updatePrices",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}, {
"name": "_rpid",
"type": "uint256"
}, {
"name": "_dates",
"type": "uint256[]"
}],
"name": "inventoriesOfDate",
"outputs": [{
"name": "",
"type": "uint16[]"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": true,
"inputs": [],
"name": "newOwner",
"outputs": [{
"name": "",
"type": "address"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_rpid",
"type": "uint256"
}],
"name": "removeRatePlan",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_newOwner",
"type": "address"
}],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_rpid",
"type": "uint256"
}, {
"name": "_dates",
"type": "uint256[]"
}, {
"name": "_inventory",
"type": "uint16"
}],
"name": "updateInventories",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"inputs": [{
"name": "_dataSource",
"type": "address"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_vendor",
"type": "address"
}, {
"indexed": false,
"name": "_name",
"type": "string"
}, {
"indexed": true,
"name": "_ipfs",
"type": "bytes32"
}],
"name": "RatePlanCreated",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_vendor",
"type": "address"
}, {
"indexed": true,
"name": "_rpid",
"type": "uint256"
}],
"name": "RatePlanRemoved",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_vendor",
"type": "address"
}, {
"indexed": true,
"name": "_rpid",
"type": "uint256"
}, {
"indexed": false,
"name": "name",
"type": "string"
}, {
"indexed": false,
"name": "_ipfs",
"type": "bytes32"
}],
"name": "RatePlanModified",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_rpid",
"type": "uint256"
}],
"name": "RatePlanPriceChanged",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_rpid",
"type": "uint256"
}],
"name": "RatePlanInventoryChanged",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_rpid",
"type": "uint256"
}],
"name": "RatePlanBasePriceChanged",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "from",
"type": "address"
}, {
"indexed": true,
"name": "to",
"type": "address"
}],
"name": "OwnershipTransferred",
"type": "event"
}, {
"constant": false,
"inputs": [],
"name": "destroy",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}];
var Utils = {
/**
* Convert IPFS address from base58 to hex format(begin with 0x)
* @param {String} ipfs IPFS address with base58 encoded
* @returns {String} IPFS with hex format(begin with 0x)
*/
ipfsBase58ToHex: function ipfsBase58ToHex(ipfs) {
var ipfsBuffer = bs58.decode(ipfs);
var ipfsHexString = ipfsBuffer.toString('hex');
if (ipfsHexString.length != 68) {
return null;
}
ipfsHexString = '0x' + ipfsHexString.slice(4);
return ipfsHexString;
}
};
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; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* RoomNightVendor
* @class
*/
var RoomNightVendor = function () {
function RoomNightVendor(web3, contractAddress, options) {
_classCallCheck(this, RoomNightVendor);
this.web3 = web3;
this.contract = this.web3.eth.contract(VABI).at(contractAddress);
}
/**
* Get inventories of dates
* @param {Number} vendorId - Vendor id
* @param {Number} rpid - Rateplan id
* @param {Number} dates - Dates E.g: [20180610,20180611]
* @param {Object} options
* @returns {Promise}
*/
_createClass(RoomNightVendor, [{
key: 'inventoriesOfDate',
value: function inventoriesOfDate(vendorId, rpid, dates, options) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.contract.inventoriesOfDate(vendorId, rpid, dates, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve(res[0]);
}
});
});
}
/**
* Get prices of dates
* @param {Number} vendorId - Vendor id
* @param {Number} rpid - Rateplan id
* @param {Number} dates - Dates E.g: [20180610,20180611]
* @param {Number} token - Token id
* @param {Object} options
* @returns {Promise}
*/
}, {
key: 'pricesOfDate',
value: function pricesOfDate(vendorId, rpid, dates, token, options) {
var _this2 = this;
return new Promise(function (resolve, reject) {
_this2.contract.pricesOfDate(vendorId, rpid, dates, token, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve(res);
}
});
});
}
/**
* Get price and inventory of date
* @param {Number} vendorId - Vendor id
* @param {Number} rpid - Rateplan id
* @param {Number} date - Date E.g: 20180630
* @param {Number} token - Token id
* @param {Object} options
* @returns {Promise} {inventory: Number, price: Number}
* * inventory: Inventory
* * price: Price
*/
}, {
key: 'priceOfDate',
value: function priceOfDate(vendorId, rpid, date, token, options) {
var _this3 = this;
return new Promise(function (resolve, reject) {
_this3.contract.priceOfDate(vendorId, rpid, date, token, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve({
inventory: res[0],
price: res[1]
});
}
});
});
}
/**
* Get rateplans of vendor by vendor id
* @param {Number} vendorId - Vendor id
* @param {Number} offset - The begin id, if id = 0 search from the begin
* @param {Number} limit - The limit of one page
* @param {Object} options
* @returns {Promise} {rateplanIds: Number, nextRateplanId: Number}
* * rateplanIds: Rateplan ids
* * nextRateplanId: The next id of rateplan, if id = 0 the next rateplan is null
*/
}, {
key: 'ratePlansOfVendor',
value: function ratePlansOfVendor(vendorId, offset, limit, options) {
var _this4 = this;
return new Promise(function (resolve, reject) {
_this4.contract.ratePlansOfVendor(vendorId, offset, limit, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve({
rateplanIds: res[0],
nextRateplanId: res[1]
});
}
});
});
}
/**
* Get rateplan information by vendor id and rateplan id
* @param {Number} vendorId - Vendor id
* @param {Number} rpid - Rateplan id
* @param {Object} options
* @returns {Promise} {name: String, createTime: Number, ipfsAddress: String}
* * name: Rateplan name
* * createTime: Create time: UTC timestamp(s)
* * ipfsAddress: IPFS file address
*/
}, {
key: 'ratePlanOfVendor',
value: function ratePlanOfVendor(vendorId, rpid, options) {
var _this5 = this;
return new Promise(function (resolve, reject) {
_this5.contract.ratePlanOfVendor(vendorId, rpid, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve({
name: res[0],
createTime: res[1],
ipfsAddress: res[2]
});
}
});
});
}
/**
* Get prices and inventories by vendor id, rateplan id, dates, token id
* @param {Number} vendorId - Vendor id
* @param {Number} rpid - Rateplan Id
* @param {Array} dates - Date E.g: [20180610,20180611]
* @param {Number} token - Token id
* @param {Object} options
* @returns {Promise} {prices: Array, inventorys: Array}
* * prices: Prices
* * inventorys: Inventories
*/
}, {
key: 'pricesAndInventoriesOfDate',
value: function pricesAndInventoriesOfDate(vendorId, rpid, dates, token, options) {
var _this6 = this;
return new Promise(function (resolve, reject) {
_this6.contract.pricesAndInventoriesOfDate(vendorId, rpid, dates, token, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve({
prices: res[0],
inventorys: res[1]
});
}
});
});
}
/**
* Update prices and inventory of rateplan
* @param {Number} rpid - Rateplan Id
* @param {Array} dates - Date E.g: [20180610,20180611]
* @param {Number} inventory - Inventory
* @param {Array} tokens - Token ids
* @param {Array} prices - Prices of tokens
* @param {Object} options
* @returns {Promise} {tx: String, rpid: Number}
* * tx: Transaction address
* * rpid: Rateplan Id
*/
}, {
key: 'updatePrices',
value: function updatePrices(rpid, dates, inventory, tokens, prices, options) {
var _this7 = this;
return new Promise(function (resolve, reject) {
_this7.contract.updatePrices(rpid, dates, inventory, tokens, prices, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this7.contract.RatePlanPriceChanged(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
rpid: res[0]
});
}
});
}
});
});
}
/**
* Update inventories of rateplan
* @param {Number} rpid - Rateplan Id
* @param {Array} dates - Date E.g: [20180610,20180611]
* @param {Number} inventory - Inventory
* @param {Object} options
* @returns {Promise} {tx: String, rpid: Number}
* * tx: Transaction address
* * rpid: Rateplan Id
*/
}, {
key: 'updateInventories',
value: function updateInventories(rpid, dates, inventory, options) {
var _this8 = this;
return new Promise(function (resolve, reject) {
_this8.contract.updateInventories(rpid, dates, inventory, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this8.contract.RatePlanInventoryChanged(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
rpid: res[0]
});
}
});
}
});
});
}
/**
* Update the base price of all rateplans
* @param {Number} rpid - Rateplan Id
* @param {Array} tokens - Token ids
* @param {Array} prices - Prices of tokens
* @param {Number} inventory - Inventory
* @param {Object} options
* @returns {Promise} {tx: String, rpid: Number}
* * tx: Transaction address
* * rpid: Rateplan Id
*/
}, {
key: 'updateBasePrice',
value: function updateBasePrice(rpid, tokens, prices, inventory, options) {
var _this9 = this;
return new Promise(function (resolve, reject) {
_this9.contract.updateBasePrice(rpid, tokens, prices, inventory, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this9.contract.RatePlanBasePriceChanged(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
rpid: res[0]
});
}
});
}
});
});
}
/**
* Create new rateplan
* @param {String} name - Rateplan name
* @param {String} ipfs - The IPFS's address of rateplan's desc
* @param {Object} options
* @returns {Promise} {tx: String, vendorId: String, name: String, ipfs: String}
* * tx: Transaction address
* * vendorId: Vendor Id
* * name: Rateplan name
* * ipfs: The IPFS's address of rateplan's desc
*/
}, {
key: 'createRatePlan',
value: function createRatePlan(name, ipfs, options) {
var _this10 = this;
var ipfsHexString = Utils.ipfsBase58ToHex(ipfs);
return new Promise(function (resolve, reject) {
_this10.contract.createRatePlan(name, ipfsHexString, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this10.contract.RatePlanCreated(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
vendorId: res[0],
name: res[1],
ipfs: res[2]
});
}
});
}
});
});
}
/**
* Remove rateplan
* @param {Number} rpid - Rateplan Id
* @param {Object} options
* @returns {Promise} {tx: String, vendorId: String, rpid: Number}
* * tx: Transaction address
* * vendorId: Vendor Id
* * rpid: Rateplan Id
*/
}, {
key: 'removeRatePlan',
value: function removeRatePlan(rpid, options) {
var _this11 = this;
return new Promise(function (resolve, reject) {
_this11.contract.removeRatePlan(rpid, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this11.contract.RatePlanRemoved(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
vendorId: res[0],
rpid: res[1]
});
}
});
}
});
});
}
/**
* Modify rateplan
* @param {Number} rpid
* @param {String} name
* @param {String} ipfs
* @param {Object} options
* @returns {Promise} {tx: String, vendorId: String, rpid: Number, name: String, ipfs: String}
* * tx: Transaction address
* * vendorId: Vendor Id
* * rpid: Rateplan Id
* * name: Rateplan name
* * ipfs: The IPFS's address of rateplan's desc
*/
}, {
key: 'modifyRatePlan',
value: function modifyRatePlan(rpid, name, ipfs, options) {
var _this12 = this;
var ipfsHexString = Utils.ipfsBase58ToHex(ipfs);
return new Promise(function (resolve, reject) {
_this12.contract.modifyRatePlan(rpid, name, ipfsHexString, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this12.contract.RatePlanModified(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
vendorId: res[0],
rpid: res[1],
name: res[2],
ipfs: res[3]
});
}
});
}
});
});
}
}]);
return RoomNightVendor;
}();
var AABI = [{
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "from",
"type": "address"
}, {
"indexed": true,
"name": "to",
"type": "address"
}],
"name": "OwnershipTransferred",
"type": "event"
}, {
"constant": false,
"inputs": [],
"name": "acceptOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_vendor",
"type": "address"
}, {
"indexed": false,
"name": "_name",
"type": "string"
}],
"name": "VendorUpdated",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_vendor",
"type": "address"
}, {
"indexed": false,
"name": "_valid",
"type": "bool"
}],
"name": "VendorValid",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_vendor",
"type": "address"
}],
"name": "VendorRemoved",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_vendor",
"type": "address"
}, {
"indexed": false,
"name": "_name",
"type": "string"
}],
"name": "VendorAdded",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"name": "_index",
"type": "uint256"
}],
"name": "TokenRemoved",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_token",
"type": "address"
}],
"name": "TokenAdded",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"name": "_uri",
"type": "string"
}],
"name": "TokenBaseURIChanged",
"type": "event"
}, {
"constant": false,
"inputs": [{
"name": "_contract",
"type": "address"
}],
"name": "addToken",
"outputs": [{
"name": "",
"type": "uint256"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_vendor",
"type": "address"
}, {
"name": "_name",
"type": "string"
}],
"name": "addVendor",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [],
"name": "destroy",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}, {
"name": "_valid",
"type": "bool"
}],
"name": "makeVendorValid",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_tokenId",
"type": "uint256"
}],
"name": "removeToken",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_vendor",
"type": "address"
}],
"name": "removeVendorByAddress",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}],
"name": "removeVendorById",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_newOwner",
"type": "address"
}],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"inputs": [{
"name": "_dataSource",
"type": "address"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}, {
"constant": false,
"inputs": [{
"name": "_uri",
"type": "string"
}],
"name": "updateBaseTokenURI",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}, {
"name": "_name",
"type": "string"
}],
"name": "updateVendorName",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_tokenId",
"type": "uint256"
}],
"name": "getToken",
"outputs": [{
"name": "_symbol",
"type": "string"
}, {
"name": "_name",
"type": "string"
}, {
"name": "_decimals",
"type": "uint8"
}, {
"name": "_token",
"type": "address"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_vendorId",
"type": "uint256"
}],
"name": "getVendor",
"outputs": [{
"name": "_name",
"type": "string"
}, {
"name": "_vendor",
"type": "address"
}, {
"name": "_timestamp",
"type": "uint256"
}, {
"name": "_valid",
"type": "bool"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_vendor",
"type": "address"
}],
"name": "getVendorByAddress",
"outputs": [{
"name": "_vendorId",
"type": "uint256"
}, {
"name": "_name",
"type": "string"
}, {
"name": "_timestamp",
"type": "uint256"
}, {
"name": "_valid",
"type": "bool"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_from",
"type": "uint256"
}, {
"name": "_limit",
"type": "uint256"
}],
"name": "getVendorIds",
"outputs": [{
"name": "",
"type": "uint256[]"
}, {
"name": "",
"type": "uint256"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": true,
"inputs": [],
"name": "newOwner",
"outputs": [{
"name": "",
"type": "address"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [{
"name": "",
"type": "address"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}, {
"constant": true,
"inputs": [{
"name": "_from",
"type": "uint256"
}, {
"name": "_limit",
"type": "uint256"
}],
"name": "supportedTokens",
"outputs": [{
"name": "",
"type": "uint256[]"
}, {
"name": "",
"type": "uint256"
}],
"payable": false,
"stateMutability": "view",
"type": "function"
}];
var _createClass$1 = 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; }; }();
function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* RoomNightAdmin
* @class
*/
var RoomNightAdmin = function () {
function RoomNightAdmin(web3, contractAddress, options) {
_classCallCheck$1(this, RoomNightAdmin);
this.web3 = web3;
this.contract = this.web3.eth.contract(AABI).at(contractAddress);
}
/**
* Get Vendor ids by page
* @param {Number} offset - The begin id, if id = 0 search from the begin
* @param {Number} limit - The limit of one page
* @param {Object} options
* @returns {Promise} {vendorIds: Number, nextVendorId: Number }
* * vendorIds: Vendor ids,
* * nextVendorId: The next id of vendor, if id = 0 the next vendor is null
*/
_createClass$1(RoomNightAdmin, [{
key: 'getVendorIds',
value: function getVendorIds(offset, limit, options) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.contract.getVendorIds(offset, limit, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve({
vendorIds: res[0],
nextVendorId: res[1]
});
}
});
});
}
/**
* Get the vendor info by id
* @param {Number} vendorId - Vendor id
* @param {Object} options
* @returns {Promise} {name: String, address: String, createTime: Number, isValid: Boolean}
* * name: Vendor name
* * address: Vendor address
* * createTime: Create time: UTC timestamp(s)
* * isValid: Vendor is valid or not
*/
}, {
key: 'getVendor',
value: function getVendor(vendorId, options) {
var _this2 = this;
return new Promise(function (resolve, reject) {
_this2.contract.getVendor(vendorId, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve({
name: res[0],
address: res[1],
createTime: res[2],
isValid: res[3]
});
}
});
});
}
/**
* Get vendor info by vendor address
* @param {String} address - Vendor address
* @param {Object} options
* @returns {Promise} {name: String, address: String, createTime: Number, isValid: Boolean}
* * name: Vendor name
* * address: Vendor address
* * createTime: Create time: UTC timestamp(s)
* * isValid: Vendor is valid or not
*/
}, {
key: 'getVendorByAddress',
value: function getVendorByAddress(address, options) {
var _this3 = this;
return new Promise(function (resolve, reject) {
_this3.contract.getVendorByAddress(address, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve({
name: res[0],
address: address,
createTime: res[2],
isValid: res[3]
});
}
});
});
}
/**
* Get all supported tokens ids
* @param {Number} offset - The begin id, if id = 0 search from the begin
* @param {Number} limit - The limit of one page
* @param {Object} options
* @returns {Promise} {tokenIds: Number, nextVendorId: Number}
* * tokenIds: Token ids
* * nextVendorId: The next id of vendor, if id = 0 the next vendor is null
*/
}, {
key: 'supportedTokens',
value: function supportedTokens(offset, limit, options) {
var _this4 = this;
return new Promise(function (resolve, reject) {
_this4.contract.supportedTokens(offset, limit, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve({
tokenIds: res[0],
nextVendorId: res[1]
});
}
});
});
}
/**
* Get token information by token id
* @param {Number} tokenId - Token id
* @param {Object} options
* @returns {Promise} {symbole: String, name: String, decimal: Number, address: String}
* * symbole: Token symbole
* * name: Token name
* * decimal: Token decimal
* * address: Token address
*/
}, {
key: 'getToken',
value: function getToken(tokenId, options) {
var _this5 = this;
return new Promise(function (resolve, reject) {
_this5.contract.getToken(tokenId, {}, function (err, res) {
if (err) {
reject(err);
} else if (res) {
resolve({
symbole: res[0],
name: res[1],
decimal: res[2],
address: res[3]
});
}
});
});
}
/**
* Update the base URI of token
* @param {String} uri - The base URI of token
* @param {Object} options
* @returns {Promise} {tx: String, uri: String}
* * tx: Transaction address
* * uri: The base URI of token
*/
}, {
key: 'updateBaseTokenURI',
value: function updateBaseTokenURI(uri, options) {
var _this6 = this;
return new Promise(function (resolve, reject) {
_this6.contract.updateBaseTokenURI(uri, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this6.contract.TokenBaseURIChanged(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
uri: res[0]
});
}
});
}
});
});
}
/**
* Add vendor
* @param {String} address - Vendor address
* @param {String} name - Vendor name
* @param {Object} options
* @returns {Promise} {tx: String, address: String, name: String}
* * tx: Transaction address
* * address: Vendor address
* * name: Vendor name
*/
}, {
key: 'addVendor',
value: function addVendor(address, name, options) {
var _this7 = this;
return new Promise(function (resolve, reject) {
_this7.contract.addVendor(address, name, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this7.contract.VendorAdded(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
address: res[0],
name: res[1]
});
}
});
}
});
});
}
/**
* Remove vendor by vendor address
* @param {String} address - Vendor address
* @param {Object} options
* @returns {Promise} {tx: String, address: String}
* * tx: Transaction address
* * address: Vendor address
*/
}, {
key: 'removeVendorByAddress',
value: function removeVendorByAddress(address, options) {
var _this8 = this;
return new Promise(function (resolve, reject) {
_this8.contract.removeVendorByAddress(address, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this8.contract.VendorRemoved(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
address: res[0]
});
}
});
}
});
});
}
/**
* Remove vendor by vendor id
* @param {Number} vendorId - Vendor id
* @param {Object} options
* @returns {Promise} {tx: String, address: String}
* * tx: Transaction address
* * address: Vendor address
*/
}, {
key: 'removeVendorById',
value: function removeVendorById(vendorId, options) {
var _this9 = this;
return new Promise(function (resolve, reject) {
_this9.contract.removeVendorById(vendorId, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this9.contract.VendorRemoved(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
address: res[0]
});
}
});
}
});
});
}
/**
* Make vendor valid or invalid
* @param {Number} vendorId - Vendor id
* @param {Boolean} valid - Vendor is valid or not
* @param {Object} options
* @returns {Promise} {tx: String, address: String, valid: Boolean}
* * tx: Transaction address
* * address: Vendor address
* * valid: Vendor is valid or not
*/
}, {
key: 'makeVendorValid',
value: function makeVendorValid(vendorId, valid, options) {
var _this10 = this;
return new Promise(function (resolve, reject) {
_this10.contract.makeVendorValid(vendorId, valid, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this10.contract.VendorValid(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
address: res[0],
valid: res[1]
});
}
});
}
});
});
}
/**
* Add token
* @param {String} contractAddress - Token contract address
* @param {Object} options
* @returns {Promise} {tx: String, address: String}
* * tx: Transaction address
* * address: Token contract address
*/
}, {
key: 'addToken',
value: function addToken(contractAddress, options) {
var _this11 = this;
return new Promise(function (resolve, reject) {
_this11.contract.addToken(contractAddress, {
from: options.from
}, function (err, tx) {
if (err) {
reject(err);
} else {
var event = _this11.contract.TokenAdded(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
address: res[0]
});
}
});
}
});
});
}
/**
* Remove token
* @param {Number} tokenId - Token id
* @param {Object} options
* @returns {Promise} {tx: String, id: Number}
* * tx: Transaction address
* * id: Token id
*/
}, {
key: 'removeToken',
value: function removeToken(tokenId, options) {
var _this12 = this;
return new Promise(function (resolve, reject) {
_this12.contract.removeToken(tokenId, {
from: options.from
}, function (err, res) {
if (err) {
reject(err);
} else {
var event = _this12.contract.TokenRemoved(function (err, res) {
event.stopWatching();
if (err) {
reject(err);
} else {
resolve({
tx: tx,
id: res[0]
});
}
});
}
});
});
}
}]);
return RoomNightAdmin;
}();
var ABI = [{
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "from",
"type": "address"
}, {
"indexed": true,
"name": "to",
"type": "address"
}],
"name": "OwnershipTransferred",
"type": "event"
}, {
"constant": false,
"inputs": [],
"name": "acceptOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"constant": false,
"inputs": [{
"name": "_rnid",
"type": "uint256"
}, {
"name": "_isRefund",
"type": "bool"
}],
"name": "applyRefund",
"outputs": [{
"name": "",
"type": "bool"
}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"name": "_vendor",
"type": "address"
}, {
"indexed": false,
"name": "_rnid",
"type": "uint256"
}],
"name": "Refund",
"type": "event"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"name": "_customer",
"type": "address"
}, {
"indexed": true,
"name": "_rnid",
"type": "uint256"
}, {
"indexed": false,
"name": "_isRefund",
"type": "bool"
}],
"name": "ApplyRefund",
"ty