stellar-base
Advanced tools
Comparing version 9.0.0-soroban.1 to 9.0.0-soroban.2
@@ -7,4 +7,6 @@ "use strict"; | ||
exports.Contract = void 0; | ||
var _address = require("./address"); | ||
var _operation = require("./operation"); | ||
var _xdr = _interopRequireDefault(require("./xdr")); | ||
var _strkey = require("./strkey"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -28,2 +30,4 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
* @param {string} contractId - ID of the contract (ex. | ||
* `CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE`, or as a | ||
* 32-byte hex string | ||
* `000000000000000000000000000000000000000000000000000000000000000001`). | ||
@@ -33,12 +37,22 @@ */ | ||
var Contract = /*#__PURE__*/function () { | ||
// TODO: Figure out contract owner/id stuff here. How should we represent that? | ||
function Contract(contractId) { | ||
_classCallCheck(this, Contract); | ||
// TODO: Add methods based on the contractSpec (or do that elsewhere?) | ||
this._id = Buffer.from(contractId, 'hex'); | ||
try { | ||
// First, try it as a strkey | ||
this._id = _strkey.StrKey.decodeContract(contractId); | ||
} catch (_) { | ||
// If that fails, try it as a hex string | ||
// TODO: Add methods based on the contractSpec (or do that elsewhere?) | ||
var b = Buffer.from(contractId, 'hex'); | ||
if (b.length !== 32) { | ||
throw new Error('Invalid contract ID'); | ||
} | ||
this._id = b; | ||
} | ||
} | ||
/** | ||
* Returns Stellar contract ID as a hex string, ex. | ||
* Returns Stellar contract ID as a strkey, or hex string, ex. | ||
* `000000000000000000000000000000000000000000000000000000000000000001`. | ||
* @param {'hex'|'strkey'} format - format of output, defaults to 'strkey' | ||
* @returns {string} | ||
@@ -49,6 +63,24 @@ */ | ||
value: function contractId() { | ||
return this._id.toString('hex'); | ||
var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'strkey'; | ||
switch (format) { | ||
case 'strkey': | ||
return _strkey.StrKey.encodeContract(this._id); | ||
case 'hex': | ||
return this._id.toString('hex'); | ||
default: | ||
throw new Error("Invalid format: ".concat(format)); | ||
} | ||
} | ||
/** | ||
* Returns the address of this contract as an Address type. | ||
* @returns {Address} | ||
*/ | ||
}, { | ||
key: "address", | ||
value: function address() { | ||
return _address.Address.contract(this._id); | ||
} | ||
/** | ||
* Returns an operation that will invoke this contract call. | ||
@@ -55,0 +87,0 @@ * |
{ | ||
"name": "stellar-base", | ||
"version": "9.0.0-soroban.1", | ||
"version": "9.0.0-soroban.2", | ||
"description": "Low-level support library for the Stellar network.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -30,3 +30,3 @@ // TypeScript Version: 2.9 | ||
constructor(contractId: string); | ||
contractId(): string; | ||
contractId(format?: 'hex' | 'strkey'): string; | ||
call(method: string, ...params: xdr.ScVal[]): xdr.Operation<Operation.InvokeHostFunction>; | ||
@@ -33,0 +33,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
3214460
67207