Skip to content

Commit 1c1636c

Browse files
committed
add source
1 parent 2f41492 commit 1c1636c

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

__tests__/client.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const wait = ms => {
4242
}, ms)
4343
})
4444
}
45-
console.log(checkNumber)
4645
// describe("checkNumber", async () => {
4746
it("ensures that the number is positive", async () => {
4847
expect(() => checkNumber(-100, "-100")).toThrowError("-100 should be a positive number")

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@binance-chain/javascript-sdk",
3-
"version": "2.14.5",
3+
"version": "2.14.6",
44
"license": "Apache-2.0",
55
"main": "lib/index.js",
66
"scripts": {

src/client/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,19 @@ const calInputCoins = (inputs, coins) => {
108108
*/
109109
export class BncClient {
110110
/**
111-
* @param {string} server Binance Chain public url
111+
* @param {String} server Binance Chain public url
112112
* @param {Boolean} useAsyncBroadcast use async broadcast mode, faster but less guarantees (default off)
113+
* @param {Number} source where does this transaction come from (default 0)
113114
*/
114-
constructor(server, useAsyncBroadcast = false) {
115+
constructor(server, useAsyncBroadcast = false, source = 0) {
115116
if (!server) {
116117
throw new Error("Binance chain server should not be null")
117118
}
118119
this._httpClient = new HttpRequest(server)
119120
this._signingDelegate = DefaultSigningDelegate
120121
this._broadcastDelegate = DefaultBroadcastDelegate
121122
this._useAsyncBroadcast = useAsyncBroadcast
123+
this._source = source
122124
this.tokens = new TokenManagement(this)
123125
this.gov = new Gov(this)
124126
}
@@ -542,6 +544,7 @@ export class BncClient {
542544
memo: memo,
543545
msg,
544546
sequence: parseInt(sequence),
547+
source: this._source,
545548
type: msg.msgType,
546549
}
547550

src/tx/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const typePrefix = {
4848
* msg: {},
4949
* type: 'NewOrderMsg',
5050
* sequence: 29,
51+
* source: 0
5152
* };
5253
* var tx = new Transaction(rawTx);
5354
* @property {Buffer} raw The raw vstruct encoded transaction
@@ -57,6 +58,7 @@ export const typePrefix = {
5758
* @param {String} type transaction type
5859
* @param {Object} data.msg object data of tx type
5960
* @param {Number} data.sequence transaction counts
61+
* @param {Number} data.source where does this transaction come from
6062
*/
6163
class Transaction {
6264
constructor(data) {
@@ -76,6 +78,7 @@ class Transaction {
7678
this.chain_id = data.chain_id
7779
this.msgs = data.msg ? [data.msg] : []
7880
this.memo = data.memo
81+
this.source = data.source || 0 // default value is 0
7982
}
8083

8184
/**
@@ -94,7 +97,7 @@ class Transaction {
9497
"memo": this.memo,
9598
"msgs": [msg],
9699
"sequence": this.sequence.toString(),
97-
"source": "1"
100+
"source": this.source.toString()
98101
}
99102

100103
return encoder.convertObjectToSignBytes(signMsg)
@@ -154,7 +157,7 @@ class Transaction {
154157
msg: [msg],
155158
signatures: this.signatures,
156159
memo: this.memo,
157-
source: 1, // web wallet value is 1
160+
source: this.source, // sdk value is 0, web wallet value is 1
158161
data: "",
159162
msgType: txType.StdTx
160163
}

0 commit comments

Comments
 (0)