weavedb-node-client 0.28.4 → 0.28.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +55 -33
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -38,9 +38,11 @@ class SDK extends Base {
|
|
|
38
38
|
port = 1820,
|
|
39
39
|
secure,
|
|
40
40
|
cert = null,
|
|
41
|
+
rollup,
|
|
41
42
|
}) {
|
|
42
43
|
super()
|
|
43
|
-
this.
|
|
44
|
+
this.rollup = rollup
|
|
45
|
+
this.contractTxId = !isNil(rollup) ? rollup.txid : contractTxId
|
|
44
46
|
this.arweave_wallet = arweave_wallet
|
|
45
47
|
if (isNil(arweave)) {
|
|
46
48
|
if (network === "localhost") {
|
|
@@ -63,21 +65,27 @@ class SDK extends Base {
|
|
|
63
65
|
(arweave.host === "host.docker.internal" || arweave.host === "localhost"
|
|
64
66
|
? "localhost"
|
|
65
67
|
: "mainnet")
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
if (isNil(this.rollup)) {
|
|
69
|
+
const [rpc_host, rpc_port] = rpc.split(":")
|
|
70
|
+
this.secure = +rpc_port === 443 && isNil(secure) ? true : secure || false
|
|
71
|
+
this.client = new weavedb_proto.DB(
|
|
72
|
+
rpc,
|
|
73
|
+
this.secure
|
|
74
|
+
? grpc.ChannelCredentials.createSsl()
|
|
75
|
+
: grpc.credentials.createInsecure()
|
|
76
|
+
)
|
|
77
|
+
}
|
|
75
78
|
if (typeof window === "object") {
|
|
76
79
|
require("@metamask/legacy-web3")
|
|
77
80
|
this.web3 = window.web3
|
|
78
81
|
}
|
|
79
|
-
if (all(complement(isNil))([contractTxId, name, version])) {
|
|
80
|
-
this.initialize({
|
|
82
|
+
if (all(complement(isNil))([this.contractTxId, name, version])) {
|
|
83
|
+
this.initialize({
|
|
84
|
+
contractTxId: this.contractTxId,
|
|
85
|
+
name,
|
|
86
|
+
version,
|
|
87
|
+
EthWallet,
|
|
88
|
+
})
|
|
81
89
|
}
|
|
82
90
|
}
|
|
83
91
|
|
|
@@ -106,30 +114,44 @@ class SDK extends Base {
|
|
|
106
114
|
}
|
|
107
115
|
const _query = () =>
|
|
108
116
|
new Promise(ret => {
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
if (!isNil(this.rollup)) {
|
|
118
|
+
this.rollup.execUser(
|
|
119
|
+
{
|
|
120
|
+
type: "offchain",
|
|
121
|
+
nocache,
|
|
122
|
+
txid: this.contractTxId,
|
|
123
|
+
func: func,
|
|
124
|
+
query: JSON.stringify(query),
|
|
125
|
+
res: (err, res) => ret({ err, result: res }),
|
|
126
|
+
},
|
|
127
|
+
"__admin__"
|
|
128
|
+
)
|
|
129
|
+
} else {
|
|
130
|
+
this.client.query(request, (err, response) => {
|
|
131
|
+
if (!isNil(err)) {
|
|
132
|
+
ret({ result: null, err })
|
|
133
|
+
} else {
|
|
134
|
+
if (response.err === "") {
|
|
135
|
+
try {
|
|
136
|
+
const result =
|
|
137
|
+
response.result === "" ? null : JSON.parse(response.result)
|
|
138
|
+
if (!isNil(result?.result?.transaction?.id)) {
|
|
139
|
+
result.getResult = async () =>
|
|
140
|
+
await this.node({
|
|
141
|
+
op: "tx_result",
|
|
142
|
+
txid: result?.result?.transaction?.id,
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
ret({ result, err: null })
|
|
146
|
+
} catch (e) {
|
|
147
|
+
ret({ result: null, err: e })
|
|
123
148
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
ret({ result: null, err: e })
|
|
149
|
+
} else {
|
|
150
|
+
ret({ result: null, err: response.err })
|
|
127
151
|
}
|
|
128
|
-
} else {
|
|
129
|
-
ret({ result: null, err: response.err })
|
|
130
152
|
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
153
|
+
})
|
|
154
|
+
}
|
|
133
155
|
})
|
|
134
156
|
let q = await _query()
|
|
135
157
|
if (!isNil(q.err)) throw new Error(q.err)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weavedb-node-client",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.6",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"@grpc/proto-loader": "^0.5.0",
|
|
12
12
|
"arweave": "^1.12.2",
|
|
13
13
|
"ramda": "^0.28.0",
|
|
14
|
-
"weavedb-base": "^0.28.
|
|
14
|
+
"weavedb-base": "^0.28.6"
|
|
15
15
|
}
|
|
16
16
|
}
|