Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
3fa102c
feat: core tx model
Dec 16, 2022
b3da8a8
feat: porting EventAttributeType
Dec 20, 2022
8e57ca4
fix: typo
Dec 20, 2022
57d75d0
feat: porting RawEventTypes
Dec 21, 2022
b90de1a
fix: add getSignerAddresses
Dec 21, 2022
b7e2de2
chore: a little refactor
Dec 21, 2022
f919a68
fix: load json as rawTransactionResult
Dec 21, 2022
dcfa016
Merge pull request #73 from ryukato/no-issue-port-core-tx-model
ryukato Dec 22, 2022
7a34a23
feat: rawTransactionAdapter skeleton
Dec 22, 2022
30ee697
Merge pull request #74 from ryukato/no-issue-port-raw-tx-model
ryukato Dec 22, 2022
e231edd
Merge branch 'release/v1.4.0' into no-issue-porting-json-raw-tx-resul…
Dec 22, 2022
d0bb177
typo fixed
Dec 22, 2022
f4b39ba
Merge pull request #76 from chansun/readme_typo
ryukato Dec 24, 2022
6f72557
feat: adapting events
Dec 26, 2022
d221ddc
feat: v2 APIs
Dec 27, 2022
4e75544
fix: typo in file name
Dec 27, 2022
64d71e7
Merge pull request #75 from ryukato/no-issue-porting-json-raw-tx-resu…
ryukato Dec 27, 2022
d90aaa8
fix: add more events
Dec 27, 2022
897d52f
fix: porting exceptions
Dec 28, 2022
439068a
fix: remove duplicated properties caused by using super type
Dec 28, 2022
1abe367
fix: implement LbdTxResultAdapter
Dec 28, 2022
e956868
fix: refactor types and util
Dec 28, 2022
842edce
Merge pull request #80 from ryukato/no-issue-more-exceptions-from-ada…
xymz Dec 29, 2022
72e137a
Merge pull request #79 from ryukato/no-issue-add-more-events
xymz Dec 29, 2022
b7dcfa5
Merge pull request #81 from ryukato/no-issue-implement-lbd-tx-result-…
xymz Dec 29, 2022
bdccc73
feat: account, baseCoin, token event handling
Dec 29, 2022
0bf224f
fix: all conflicts
Dec 29, 2022
fe9e5ab
Merge pull request #1 from line/release/v1.4.0
chansun Dec 30, 2022
fb01f71
feat: handle coin and token events
Jan 2, 2023
8e3db98
docs: add docs for new tx-result
Jan 2, 2023
8c1bf4f
feat: add all events handle functions
Jan 2, 2023
ddab107
chore: fix typo
Jan 2, 2023
7c0e291
Merge pull request #78 from ryukato/no-issue-v2-user-tx-history-api
ryukato Jan 3, 2023
cd5a63b
fix: typo
Jan 3, 2023
a936605
Merge branch 'line:release/v1.4.0' into release/v1.4.0
chansun Jan 3, 2023
b6b4480
remove typo
Jan 3, 2023
97aee80
logger switch added
Jan 3, 2023
98e6a1c
Merge pull request #82 from ryukato/no-issue-handle-events
ryukato Jan 3, 2023
24a1204
Merge pull request #83 from ryukato/no-issue-add-docs-for-new-tx-result
ryukato Jan 3, 2023
2b4db83
chore: fixed gitignore for macosx
Jan 3, 2023
b771fb0
chore: fixed vulnerable dependency
Jan 3, 2023
0677958
chores: added newlines if not added
Jan 3, 2023
0e0ddf1
chore: removed invalid files
Jan 3, 2023
d98a54a
Merge pull request #87 from xymz/chores
ryukato Jan 3, 2023
ab4255f
Add missing raw transaction log creation code
junbae2 Jan 3, 2023
6de7cf0
remove fake logger and exec() function
Jan 3, 2023
b824677
new line added
Jan 3, 2023
c6ca437
Merge pull request #85 from junbae2/add-missing-raw-transaction-log-c…
junbae2 Jan 3, 2023
e6ada6d
Fix RawTransactionLogUtil.findEvent bug
junbae2 Jan 3, 2023
9e69b64
fix a broken test
junbae2 Jan 3, 2023
2800c8e
Merge pull request #86 from chansun/release/v1.4.0
xymz Jan 3, 2023
fe066b8
Merge pull request #88 from junbae2/fix-find-event-bug
ryukato Jan 3, 2023
7c5109f
Add empty account resolver to LbdTxEventsAdapterV1
junbae2 Jan 4, 2023
e0bda78
Add token event resolver to LbdTxEventsAdapterV1
junbae2 Jan 4, 2023
b208a6a
Fix broken tests
junbae2 Jan 5, 2023
e110be3
Implement transaction event resolvers. collection
junbae2 Jan 5, 2023
63ef146
Merge pull request #89 from junbae2/no-issue-event-adapter-token
ryukato Jan 5, 2023
3889a0f
Remove compiled ts resources
junbae2 Jan 9, 2023
d5dd390
Rollback es2017 to es2019 in tsconfig
junbae2 Jan 9, 2023
0e81a1d
Merge pull request #91 from junbae2/no-issue-event-adapter-collection
ryukato Jan 9, 2023
a27a983
chore: version up
Jan 9, 2023
6b64934
Merge pull request #92 from ryukato/no-issue-version-bump-up
ryukato Jan 12, 2023
3f9e1ab
fix: typo and add link to guide for tx-result adapters
Jan 31, 2023
766ab0f
fix: export omitted classes and resolve conflicted class names
Jan 31, 2023
a0760a6
Merge pull request #96 from xymz/refact/tx-messages
ryukato Jan 31, 2023
8f1e327
Merge pull request #95 from ryukato/no-issue-fix-document-for-tx-adap…
xymz Jan 31, 2023
ef1371d
refact: reindent(use editorconfig)
Feb 1, 2023
26ed987
refact: use Array instead of Set in TxResultSummary, TxResult
Feb 1, 2023
6434cea
refact: use Array instead of Set in EventTokenModified
Feb 1, 2023
2d2e861
refact: use Array instead of Set in EventCollectionModified
Feb 1, 2023
235e785
refact: use Array instead of Set in EventCollectionFtModified
Feb 1, 2023
5bcb6d9
refact: use Array instead of Set in EventCollectionNftBurned/EventCol…
Feb 1, 2023
ae306a5
refact: use Array instead of Set in rest of classes in tx-core-models
Feb 1, 2023
1edad0c
Merge pull request #97 from xymz/refact/tx-core-models
ryukato Feb 1, 2023
ff83462
fix: use empty string instead of null
Feb 2, 2023
01f4c0f
Merge pull request #99 from xymz/refact/tx-core-models
ryukato Feb 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Please put the example code where you find the bug
#### Error logs
Please add error logs from the bug

### Anything else we need to know
### Anything else we need to know
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ coverage
package-lock.json
*.env
dist
*.tsbuildinfo
*.tsbuildinfo
.DS_Store
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# package.json is formatted by package managers, so we ignore it here
package.json
package.json
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![CircleCI](https://circleci.com/gh/line/line-blockchain-developers-sdk-js.svg?style=shield)](https://circleci.com/gh/line/line-blockchain-developers-sdk-js)


## Table of Contents // TODO update
## Table of Contents
* [Introduction](#introduction)
* [Getting Started](#getting-Started)
* [Key objects and usage](#key-objects-and-usage)
Expand Down Expand Up @@ -218,7 +218,7 @@ import { GenericResponse, TxResultResponse } from './lib/response';

(async() => {
const request = new MemoRequest('my first memo', walletAddress, walletSecret);
let response: GenericResponse<TxResultResponse> = await httpClient.createMemo(servcieId);
let response: GenericResponse<TxResultResponse> = await httpClient.createMemo(request);
console.log(response.responseData.txhash);
})();
```
Expand All @@ -231,3 +231,5 @@ All API requests, except for the endpoint to retrieve the server time, must pass
If you do want to study how LINE Blockchain signature created, it's okay to dive into the source code.


### New transaction result
Please refer to [New transaction result](./docs/README.md)
2 changes: 1 addition & 1 deletion developers-sdk-js.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"path": "."
}
]
}
}
271 changes: 271 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
## Getting Started
### Requirements
* Node.js >= 10
* It uses ES2017.

* [npm](https://www.npmjs.com/?target=_blank), preferably >=7

Other dependencies are installed via npm(or yarn), and do not need to be pre-installed.

### Install
All the dependencies can be installed via [npm](https://www.npmjs.com/?target=_blank) or [yarn](https://yarnpkg.com/?target=_blank)

* [npm](https://www.npmjs.com/?target=_blank)
```
npm install @line/lbd-sdk-js
```

* [yarn](https://yarnpkg.com/?target=_blank)
```
yarn add @line/lbd-sdk-js
```

Instead of using package managers, you can clone and build from source as well. Run the following scripts/commends.

```
$ git clone https://github.com/line/line-blockchain-developers-sdk-js.git
$ cd line-blockchain-developers-sdk-js
$ npm install
$ npm run build
```
The built result will be placed in `build/`.

#### Test
You can run all the unit tests by following scripts.

```
npm run test
```

#### Integration tests
You can **run** all the integration tests by following scripts.

```
npm run test:integration
```

> Note
>
> To run integration tests, `integration-test.env` is required with following properties.
```
HOST_URL=[api-url]
SERVICE_ID=[your service-id]
SERVICE_API_KEY=[your service-api-key]
SERVICE_API_SECRET=[your service-api-secret]
OWNER_ADDRESS=[your service wallet address]
OWNER_SECRET=[your service wallet secret]
OWNER_ADDRESS2=[your another service wallet address]
SERVICE_TOKEN_CONTRACT_ID=[your service-token contract-id]
ITEM_TOKEN_CONTRACT_ID=[your item-token contract-id]
LINE_USER_ID=[your line user id]
LINE_USER_WALLET_ADDRESS=[BitMax wallet address of the user]
```

### Basic Usage
It can be imported with [CommonJS](https://nodejs.org/docs/latest/api/modules.html?target=_blank), [ES2015 modules](https://babeljs.io/learn-es2015/#ecmascript-2015-features-modules?target=_blank), and preferably [TypeScript](https://www.typescriptlang.org/?target=_blank).

The library is written in TypeScript and includes TypeScript definitions by default. Nevertheless, it can surely be used with plain JavaScript too.

#### Create HttpClient
```
// CommonJS
const devSdk = require('@line/lbd-sdk-js');
const httpClient = new devSdk.HttpClient(BASE_URL, SERVICE_API_KEY, SERVICE_API_SECRET)

// ES2015 modules or TypeScript
import * as devSdk from '@line/lbd-sdk-js';
const httpClient = new devSdk.HttpClient(BASE_URL, SERVICE_API_KEY, SERVICE_API_SECRET)

```

#### Example to get server time
##### Using promise
```JavaScript
httpClient.time().then(response => {
console.log("statusCode", response.statusCode);
console.log("responseTime", response.responseTime);
console.log("statusMessage", response.statusMessage);
console.log("responseData", response.responseData);
})
```

##### Using async function
```JavaScript
async function checkServerTime() {
var response = await httpClient.time();
console.log("statusCode", response.statusCode);
console.log("responseTime", response.responseTime);
console.log("statusMessage", response.statusMessage);
console.log("responseData", response.responseData);
}
```

## Key objects and usage
### `HttpClient`
This class represents an HTTP client to connect and interact with the LINE Blockchain Developers API server. It provides functions to call the endpoints of the API with mandatory and optional parameters.
It's an entry point for this library, every dApp for LINE Blockchain Developers should have an instance of `HttpClient`.

Create an instance with your connection and authentication information as follows:

```JavaScript
// Directly import
import { HttpClient } from './lib/http-client-base';
const httpClient = new HttpClient(baseUrl, apiKey, apiSecret);

// CommonJS
const devSdk = require('@line/lbd-sdk-js');
const httpClient = new devSdk.HttpClient(BASE_URL, SERVICE_API_KEY, SERVICE_API_SECRET)

// ES2015 modules or TypeScript
import * as devSdk from '@line/lbd-sdk-js';
const httpClient = new devSdk.HttpClient(BASE_URL, SERVICE_API_KEY, SERVICE_API_SECRET)
```

- `baseUrl` is the address of API server. Find one for the chain your service runs on in [API guide](https://docs-blockchain.line.biz/api-guide/).
- `apiKey` is your service's API key.
- `apiSecret` is your service's API secret. **Never** use the secret hard-coded in the source code.

Now, you can call any endpoints via the functions of the instance. A simple example is to get the server time:

```JavaScript
(async() => {
const response = await httpClient.time();
console.log(response['statusCode']);
})();
```

Remember that you must handle it in an asynchronous way.

### Request and response
When requesting, you can use predefined request data classes in `lib/request.ts`. Try to send a memo save request for example as follows:

```JavaScript
//Directly import
import { MemoRequest } from './lib/request';

(async() => {
const request = new MemoRequest('my first memo', walletAddress, walletSecret);
const response = await httpClient.createMemo(request);
})();
```

When you need to parse a JSON-formatted `responseData` in a response, find and use the proper response data class in `lib/response.ts`. To get the `txhash` or the above request for example:

```JavaScript
import { GenericResponse, TxResultResponse } from './lib/response';

(async() => {
const request = new MemoRequest('my first memo', walletAddress, walletSecret);
let response: GenericResponse<TxResultResponse> = await httpClient.createMemo(request);
console.log(response.responseData.txhash);
})();
```

### `SignatureGenerator`
This class provides a functionality to [generate signatures](https://docs-blockchain.line.biz/api-guide/Authentication#generating-signature) for a request.

All API requests, except for the endpoint to retrieve the server time, must pass authentication information and be signed. Signing is a bit annoying, but never mind, fortunately, `HttpClient` itself will import this and generate signatures before sending a request.

If you do want to study how LINE Blockchain signature created, it's okay to dive into the source code.


### New transaction result
LINE Blockchain Developers provide custom transaction result that is independent from on-chain transaction result, and it is more simple and understand. The new transaction result has summary, messages and events in following structure. For more details, please visit [LINE Blockchain Docs](https://docs-blockchain.line.biz/api-guide/Callback-Response)

```
{
"summary": {
"height": number,
"txIndex" : number,
"txHash"": string,
"signers": Array<string>,
"result: {
"code": number,
"codeSpace": string,
"result": string ("SUCCEEDED", or "FAILED")
}
},
"txMessages": [
{
"msgIndex": number,
"requestType": string,
"details": any (* object)
}
],
"txEvents": [
"eventName": string,
"msgIndex": number,
... // more properties depending on each concrete event
],
}
```

#### Summary
"summary" has `height`, `txIndex`, `txHash`, `signers` and `result`. More details on each property are as followings.
* height: block height
* txIndex: this means n-th transaction in a block
* txHash: hash string for a transaction
* signers: wallet addresses of those who signs a transaction
* result: this has `code`, `codeSpace` and `result`.
* code: this is a sort of error code, and if it is not `0`, then it means the transaction has been failed.
* codeSpace: Namespace of `code`
* Status of the transaction confirmation displayed as either of the following.
* SUCCEEDED: Confirmation successful
* FAILED: Confirmation failed


### txMessages
There could be messages more than one in a transaction, and a message is what a client wants to mutate such as transfer coin or token, mint, burn and so on.
A message has `msgIndex`, `requestType` and `details`. More details on each property are as followings.
* msgIndex: Index number of the message in a transaction
* requestType: Type of the message. For example, "collection/MsgTransferNFT"
* details: Value included in the message. Properties vary, depending on the type of the message.

> Note
>
> `details` in each message isn't a fixed object, since it's hard to provide a concrete type of data when we support smart contract. With smart contracts, developers or owners of the smart contract can define their own messages with custom properties, which are not known to LINE Blockchain Developers.

### txEvents
Event refers to a change in status, triggered by a confirmed transaction. Events are distinguished as base coin related events, service token related events and item token related events. Refer to [LINE Blockchain Docs](https://lbddocs-alpha.website.line-apps-dev.com/api-guide/Callback-Response#event) for event names and their properties for each type.

By they way, all events basically have `msgIndex` and `eventName` properties.
* msgIndex: Index number of the message caused events.
* eventName: Name of an event such as `EventCoinTransferred`, `EventTokenIssued` and so on.

### Adapting to new transaction result
We need a way to adapt(convert) old transaction result in sort of raw format, which is very dependent on the chain's to new structured transaction result.

#### Basic adapting flow
Adapting flow is simple as below.
```
Old(current) transaction result ---> raw-transaction result ---> new structured transaction result.
```

#### How to adapt old one to new one.
##### Adapting(converting) to raw-transaction result

```
...
const rawTransactionResultAdapter: TxResultAdapter<TxResultResponse, RawTransactionResult> = new RawTransactionResultAdapter();
// using default adapters for summary, messages and events
const lbdTxResultAdapter: TxResultAdapter<RawTransactionResult, TxResult> = new LbdTxEventsAdapterV1(HrpPrefix.TEST_NET);

/*
We can use custom adapters for summary, messages and events
const customTxResultSummaryAdapter: TxResultAdapter<RawTransactionResult, TxResultSummary> = new CustomTxSummaryAdapterV1();
const customTxMessagesAdapter: TxResultAdapter<RawTransactionResult, Array<TxMessage>> = new CustomTxMessageAdapterV1();
const customTxEventsAdapter: TxResultAdapter<RawTransactionResult, Array<TransactionEvent>> = new CustomTxMessageAdapterV1();

const lbdTxResultAdapter: TxResultAdapter<RawTransactionResult, TxResult> = new LbdTxEventsAdapterV1(
HrpPrefix.TEST_NET,
customTxResultSummaryAdapter ,
customTxMessagesAdapter,
customTxEventsAdapter
);
*/

let txResultResponse = lbdHttpClient.transactionResult(txHash);
let rawTransactionResult = rawTransactionResultAdapter.adapt(txResultResponse.responseData);
let newTransactionResult = lbdTxResultAdapter.adapt(rawTransactionResult);
...
```
Empty file added docs/lbd-new-tx-result.md
Empty file.
2 changes: 1 addition & 1 deletion examples/commonJsExample/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
}
2 changes: 1 addition & 1 deletion examples/commonJsExample/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ async function checkServerTime() {
console.log("responseData", response.responseData);
}

checkServerTime();
checkServerTime();
2 changes: 1 addition & 1 deletion examples/es5Example/sdkClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ class SdkClient {
}

const sdkClient = new SdkClient();
export { sdkClient };
export { sdkClient };
1 change: 0 additions & 1 deletion integration-test/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('http-client-base test', () => {
const httpClient = new HttpClient(HOST_URL, SERVICE_API_KEY, SERVICE_API_SECRET);

it('time api test', async () => {
1

const response = await httpClient.time();
expect(response["statusCode"]).to.equal(1000);
Expand Down
27 changes: 27 additions & 0 deletions lib/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export class DenomAmount {
constructor(
readonly amount: string,
readonly denomination: string,
) { }

public static create(obj: any): DenomAmount {
return new DenomAmount(
obj["amount"],
obj["denom"] ?? obj["denomination"]
)
}
}

export class TokenIdAmount {
constructor(
readonly amount: string,
readonly tokenId: string,
) { }

public static create(obj: any): TokenIdAmount {
return new TokenIdAmount(
obj["amount"],
obj["tokenId"]
)
}
}
10 changes: 9 additions & 1 deletion lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ export class Validations {
static PATTERN_URI_PATH = "[\\w\\.\\-\\~\\/]+"
static PATTERN_BASE_URI = `^(https:\\/\\/)${Validations.PATTERN_URI_PATH}(:[0-9]{1,5})?\\/$`
static BASE_URI_OR_EMPTY_REGEX = new RegExp(`^(${Validations.PATTERN_BASE_URI})?$`)
}
}

export enum HrpPrefix {
MAIN_NET = "link", TEST_NET = "tlink",
}

export const EMPTY_SET: Set<string> = new Set();

export const EMPTY_STRING_ARRAY: Array<string> = [];
Loading