Skip to content

Commit

Permalink
Handle passing in an array of tokenIds to /list
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cardona committed Feb 22, 2019
1 parent e306040 commit badf84c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 33 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
[SLP SDK](https://developer.bitcoin.com/slp) is powered by [BITBOX](https://developer.bitcoin.com/bitbox).

## Installation and Usage

- Ensure you have node.js v10 or higher installed.

- Clone this repository

```bash
git clone https://github.com/Bitcoin-com/slp-sdk
cd slp-sdk
Expand All @@ -26,5 +28,6 @@ cd slp-sdk
- [SLP specification unit tests](https://github.com/simpleledger/slp-unit-test-data) (Python)

### Token-Aware Wallets

- [Badger Wallet](https://badger.bitcoin.com/)
- [Electron Cash SLP](https://github.com/simpleledger/Electron-Cash-SLP)
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const repl = require("repl")
const SLP = require("./lib/SLP").default
const clone = require("git-clone")

program.version("1.3.1", "-v, --version")
program.version("2.0.0", "-v, --version")

program
.command("new <name>")
Expand Down
31 changes: 24 additions & 7 deletions lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,44 @@ var Utils = /** @class */ (function () {
}
Utils.prototype.list = function (id) {
return __awaiter(this, void 0, void 0, function () {
var path, response, error_1;
var path, method, response, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!id)
if (!id) {
method = "get";
path = this.restURL + "slp/list";
else
}
else if (typeof id === "string") {
method = "get";
path = this.restURL + "slp/list/" + id;
}
else if (typeof id === "object") {
method = "post";
path = this.restURL + "slp/list";
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
_a.trys.push([1, 6, , 7]);
response = void 0;
if (!(method === "get")) return [3 /*break*/, 3];
return [4 /*yield*/, axios_1.default.get(path)];
case 2:
response = _a.sent();
return [2 /*return*/, response.data];
case 3:
return [3 /*break*/, 5];
case 3: return [4 /*yield*/, axios_1.default.post(path, {
tokenIds: id
})];
case 4:
response = _a.sent();
_a.label = 5;
case 5: return [2 /*return*/, response.data];
case 6:
error_1 = _a.sent();
if (error_1.response && error_1.response.data)
throw error_1.response.data;
throw error_1;
case 4: return [2 /*return*/];
case 7: return [2 /*return*/];
}
});
});
Expand Down
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slp-sdk",
"version": "1.3.1",
"version": "2.0.0",
"description": "SLP SDK powered by BITBOX",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -31,7 +31,7 @@
"axios": "^0.17.1",
"babel-register": "^6.26.0",
"bignumber.js": "^7.2.1",
"bitbox-sdk": "^3.1.0",
"bitbox-sdk": "4.0.0",
"chalk": "^2.3.0",
"clear": "0.1.0",
"commander": "^2.13.0",
Expand Down
24 changes: 20 additions & 4 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,29 @@ class Utils {
this.restURL = restURL
}

async list(id: string): Promise<Object | Array<Object>> {
async list(id?: string | string[]): Promise<Object | Array<Object>> {
let path: string
if (!id) path = `${this.restURL}slp/list`
else path = `${this.restURL}slp/list/${id}`
let method: string
if (!id) {
method = "get"
path = `${this.restURL}slp/list`
} else if (typeof id === "string") {
method = "get"
path = `${this.restURL}slp/list/${id}`
} else if (typeof id === "object") {
method = "post"
path = `${this.restURL}slp/list`
}

try {
const response = await axios.get(path)
let response: any
if (method === "get") {
response = await axios.get(path)
} else {
response = await axios.post(path, {
tokenIds: id
})
}
return response.data
} catch (error) {
if (error.response && error.response.data) throw error.response.data
Expand Down

0 comments on commit badf84c

Please sign in to comment.