Skip to content

Commit 3b87fa5

Browse files
authored
Merge pull request #250 from aeternity/release/2.2.1-next
Pre-Release 2.2.1-next
2 parents 1753bba + 3c3c940 commit 3b87fa5

File tree

18 files changed

+457
-149
lines changed

18 files changed

+457
-149
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
All notable changes to this project will be documented in this file. This change
33
log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
44

5+
## [2.2.1-next]
6+
### Added
7+
- Add `deserialization` schema for `Channel` transactions(`channelCreate`, `channelCloseMutual`, `channelDeposit`, `channelWithdraw`, `channelSettle`)
8+
- Add `rawTx` and `verifyTx` to error from poll function(when you wait for transaction will mined)
9+
10+
### Changed
11+
- Change Channel `legacy` API to `JSON RPC`
12+
- Change `minFee` calculation, multiply min fee by 10^9
13+
14+
### Removed
15+
- none
16+
17+
### Breaking Changes
18+
- none
19+
20+
### Notes and known Issues
21+
- Depend on `bip39` from npm instead of git repo
22+
23+
524
## [2.1.1-0.1.0-next]
625
### Added
726
- none
@@ -464,3 +483,4 @@ log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
464483
[2.0.0]: https://github.com/aeternity/aepp-sdk-js/compare/1.3.2...2.0.0
465484
[2.1.0]: https://github.com/aeternity/aepp-sdk-js/compare/2.0.0...2.1.0
466485
[2.1.1-0.1.0-next]: https://github.com/aeternity/aepp-sdk-js/compare/2.1.0...2.1.1-0.1.0-next
486+
[2.2.1-next]: https://github.com/aeternity/aepp-sdk-js/compare/2.1.1-0.1.0-next...2.2.1-next

docker/accounts_test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi": 100000000000001000000000000000000
2+
"ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi": 100000000000001000000000000000000000
33
}

es/chain/node.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import TransactionValidator from '../tx/validator'
3434
async function sendTransaction (tx, options = {}) {
3535
const { waitMined, verify } = R.merge(this.Chain.defaults, options)
3636
// Verify transaction before broadcast
37-
if (verify) {
37+
if (this.verifyTxBeforeSend || verify) {
3838
const { validation, tx: txObject, txType } = await this.unpackAndVerify(tx)
3939
if (validation.length) {
4040
throw Object.assign({
@@ -46,7 +46,7 @@ async function sendTransaction (tx, options = {}) {
4646
}
4747

4848
const { txHash } = await this.api.postTransaction({ tx })
49-
return waitMined ? { ...(await this.poll(txHash, options)), rawTx: tx } : { hash: txHash, rawTx: tx }
49+
return waitMined ? { ...(await this.poll(txHash, options, tx)), rawTx: tx } : { hash: txHash, rawTx: tx }
5050
}
5151

5252
async function balance (address, { height, hash, format = false } = {}) {
@@ -97,7 +97,7 @@ async function topBlock () {
9797
return top[R.head(R.keys(top))]
9898
}
9999

100-
async function poll (th, { blocks = 10, interval = 5000 } = {}) {
100+
async function poll (th, { blocks = 10, interval = 5000 } = {}, raw) {
101101
const instance = this
102102
const max = await this.height() + blocks
103103

@@ -110,7 +110,12 @@ async function poll (th, { blocks = 10, interval = 5000 } = {}) {
110110
await pause(interval)
111111
return probe()
112112
}
113-
throw Error(`Giving up after ${blocks} blocks mined`)
113+
throw Object.assign(
114+
(new Error(`Giving up after ${blocks} blocks mined.`)),
115+
{
116+
verifyTx: () => instance.unpackAndVerify(raw)
117+
}
118+
)
114119
}
115120

116121
return probe()
@@ -165,6 +170,9 @@ async function txDryRun (txs, accounts, top) {
165170
* @example ChainNode({url: 'https://sdk-testnet.aepps.com/'})
166171
*/
167172
const ChainNode = Chain.compose(Node, Oracle, Contract, TransactionValidator, {
173+
init ({ verifyTx = false }) {
174+
this.verifyTxBeforeSend = verifyTx
175+
},
168176
methods: {
169177
sendTransaction,
170178
balance,

es/channel/handlers.js

Lines changed: 74 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,45 @@ import {
2626
import * as R from 'ramda'
2727

2828
export function awaitingConnection (channel, message, state) {
29-
if (message.action === 'info') {
30-
if (['channel_accept', 'funding_created'].includes(message.payload.event)) {
29+
if (message.method === 'channels.info') {
30+
if (['channel_accept', 'funding_created'].includes(message.params.data.event)) {
3131
changeStatus(channel, {
3232
channel_accept: 'accepted',
3333
funding_created: 'halfSigned'
34-
}[message.payload.event])
34+
}[message.params.data.event])
3535
return { handler: awaitingChannelCreateTx }
3636
}
37-
if (message.payload.event === 'channel_reestablished') {
37+
if (message.params.data.event === 'channel_reestablished') {
3838
return { handler: awaitingOpenConfirmation }
3939
}
4040
return { handler: awaitingConnection }
4141
}
42-
if (message.action === 'error') {
42+
if (message.method === 'channels.error') {
4343
emit(channel, 'error', new Error(message.payload.message))
4444
return { handler: channelClosed }
4545
}
4646
}
4747

4848
export async function awaitingChannelCreateTx (channel, message, state) {
49-
if (message.action === 'sign') {
50-
const signedTx = await options.get(channel).sign(message.tag, message.payload.tx)
51-
send(channel, { action: message.tag, payload: { tx: signedTx } })
49+
const tag = {
50+
initiator: 'initiator_sign',
51+
responder: 'responder_sign'
52+
}[options.get(channel).role]
53+
if (message.method === `channels.sign.${tag}`) {
54+
const signedTx = await options.get(channel).sign(message.tag, message.params.data.tx)
55+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } })
5256
return { handler: awaitingOnChainTx }
5357
}
5458
}
5559

5660
export function awaitingOnChainTx (channel, message, state) {
57-
if (message.action === 'on_chain_tx') {
58-
emit(channel, 'onChainTx', message.payload.tx)
61+
if (message.method === 'channels.on_chain_tx') {
62+
emit(channel, 'onChainTx', message.params.data.tx)
5963
return { handler: awaitingBlockInclusion }
6064
}
6165
if (
62-
message.action === 'info' &&
63-
message.payload.event === 'funding_signed' &&
66+
message.method === 'channels.info' &&
67+
message.params.data.event === 'funding_signed' &&
6468
options.get(channel).role === 'initiator'
6569
) {
6670
changeStatus(channel, 'signed')
@@ -69,59 +73,59 @@ export function awaitingOnChainTx (channel, message, state) {
6973
}
7074

7175
export function awaitingBlockInclusion (channel, message, state) {
72-
if (message.action === 'info') {
76+
if (message.method === 'channels.info') {
7377
const handler = {
7478
own_funding_locked: awaitingBlockInclusion,
7579
funding_locked: awaitingOpenConfirmation
76-
}[message.payload.event]
80+
}[message.params.data.event]
7781
if (handler) {
7882
return { handler }
7983
}
8084
}
8185
}
8286

8387
export function awaitingOpenConfirmation (channel, message, state) {
84-
if (message.action === 'info' && message.payload.event === 'open') {
88+
if (message.method === 'channels.info' && message.params.data.event === 'open') {
8589
return { handler: awaitingInitialState }
8690
}
8791
}
8892

8993
export function awaitingInitialState (channel, message, state) {
90-
if (message.action === 'update') {
91-
changeState(channel, message.payload.state)
94+
if (message.method === 'channels.update') {
95+
changeState(channel, message.params.data.state)
9296
return { handler: channelOpen }
9397
}
9498
}
9599

96100
export async function channelOpen (channel, message, state) {
97-
if (message.action === 'info') {
98-
if (message.payload.event === 'died') {
101+
if (message.method === 'channels.info') {
102+
if (message.params.data.event === 'died') {
99103
changeStatus(channel, 'died')
100104
}
101105
const handler = {
102106
update: awaitingUpdateTxSignRequest,
103107
close_mutual: channelOpen,
104108
died: channelClosed
105-
}[message.payload.event]
109+
}[message.params.data.event]
106110
if (handler) {
107111
return { handler }
108112
}
109113
}
110-
if (message.action === 'sign' && message.tag === 'shutdown_sign_ack') {
111-
const signedTx = await Promise.resolve(options.get(channel).sign(message.tag, message.payload.tx))
112-
send(channel, { action: message.tag, payload: { tx: signedTx } })
114+
if (message.method === 'channels.sign.shutdown_sign_ack') {
115+
const signedTx = await Promise.resolve(options.get(channel).sign(message.tag, message.params.data.tx))
116+
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown_sign_ack', params: { tx: signedTx } })
113117
return { handler: channelOpen }
114118
}
115-
if (message.action === 'on_chain_tx') {
116-
emit(channel, 'onChainTx', message.payload.tx)
119+
if (message.method === 'channels.on_chain_tx') {
120+
emit(channel, 'onChainTx', message.params.data.tx)
117121
return { handler: channelOpen }
118122
}
119-
if (message.action === 'leave') {
123+
if (message.method === 'channels.leave') {
120124
// TODO: emit event
121125
return { handler: channelOpen }
122126
}
123-
if (message.action === 'message') {
124-
emit(channel, 'message', message.payload.message)
127+
if (message.method === 'channels.message') {
128+
emit(channel, 'message', message.params.data.message)
125129
return { handler: channelOpen }
126130
}
127131
}
@@ -130,44 +134,44 @@ channelOpen.enter = (channel) => {
130134
}
131135

132136
export async function awaitingOffChainTx (channel, message, state) {
133-
if (message.action === 'sign' && message.tag === 'update') {
137+
if (message.method === 'channels.sign.update') {
134138
const { sign } = state
135-
const signedTx = await sign(message.payload.tx)
136-
send(channel, { action: message.tag, payload: { tx: signedTx } })
139+
const signedTx = await sign(message.params.data.tx)
140+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } })
137141
return { handler: awaitingOffChainUpdate, state }
138142
}
139-
if (message.action === 'error') {
140-
state.reject(new Error(JSON.stringify(message.payload)))
143+
if (message.method === 'channels.error') {
144+
state.reject(new Error(message.data.message))
141145
return { handler: channelOpen }
142146
}
143147
}
144148

145149
export function awaitingOffChainUpdate (channel, message, state) {
146-
if (message.action === 'update') {
147-
changeState(channel, message.payload.state)
148-
state.resolve({ accepted: true, state: message.payload.state })
150+
if (message.method === 'channels.update') {
151+
changeState(channel, message.params.data.state)
152+
state.resolve({ accepted: true, state: message.params.data.state })
149153
return { handler: channelOpen }
150154
}
151-
if (message.action === 'conflict') {
155+
if (message.method === 'channels.conflict') {
152156
state.resolve({ accepted: false })
153157
return { handler: channelOpen }
154158
}
155159
}
156160

157161
export async function awaitingUpdateTxSignRequest (channel, message, state) {
158-
if (message.action === 'sign' && message.tag === 'update_ack') {
159-
const signedTx = await options.get(channel).sign(message.tag, message.payload.tx)
162+
if (message.method === 'channels.sign.update_ack') {
163+
const signedTx = await options.get(channel).sign(message.tag, message.params.data.tx)
160164
if (signedTx) {
161-
send(channel, { action: message.tag, payload: { tx: signedTx } })
165+
send(channel, { jsonrpc: '2.0', method: 'channels.update_ack', params: { tx: signedTx } })
162166
return { handler: awaitingUpdateTx }
163167
}
164168
// soft-reject via competing update
165169
send(channel, {
166-
action: 'update',
167-
tag: 'new',
168-
payload: {
169-
from: generateKeyPair().pub,
170-
to: generateKeyPair().pub,
170+
jsonrpc: '2.0',
171+
method: 'channels.update.new',
172+
params: {
173+
from: generateKeyPair().publicKey,
174+
to: generateKeyPair().publicKey,
171175
amount: 1
172176
}
173177
})
@@ -176,63 +180,70 @@ export async function awaitingUpdateTxSignRequest (channel, message, state) {
176180
}
177181

178182
export function awaitingUpdateTx (channel, message, state) {
179-
if (message.action === 'update') {
183+
if (message.method === 'channels.update') {
184+
// TODO: change state to `message.params.data.state`
180185
return { handler: channelOpen }
181186
}
182187
}
183188

184189
export function awaitingUpdateConflict (channel, message, state) {
185-
if (message.action === 'error' && message.payload.reason === 'conflict') {
190+
if (message.error) {
186191
return { handler: awaitingUpdateConflict }
187192
}
188-
if (message.action === 'conflict') {
193+
if (message.method === 'channels.conflict') {
189194
return { handler: channelOpen }
190195
}
191196
}
192197

193198
export function awaitingProofOfInclusion (channel, message, state) {
194-
if (message.action === 'get' && message.tag === 'poi') {
195-
state.resolve(message.payload.poi)
199+
if (message.id === state.messageId) {
200+
state.resolve(message.result.poi)
196201
return { handler: channelOpen }
197202
}
198-
if (message.action === 'error') {
199-
state.reject(new Error(message.payload.reason))
203+
if (message.method === 'channels.error') {
204+
state.reject(new Error(message.data.message))
200205
return { handler: channelOpen }
201206
}
202207
}
203208

204209
export function awaitingBalances (channel, message, state) {
205-
if (message.action === 'get' && message.tag === 'balances') {
210+
if (message.id === state.messageId) {
206211
state.resolve(R.reduce((acc, item) => ({
207212
...acc,
208213
[item.account]: item.balance
209-
}), {}, message.payload))
214+
}), {}, message.result))
210215
return { handler: channelOpen }
211216
}
212-
if (message.action === 'error') {
213-
state.reject(new Error(message.payload.reason))
217+
if (message.method === 'channels.error') {
218+
state.reject(new Error(message.data.message))
214219
return { handler: channelOpen }
215220
}
216221
}
217222

218223
export async function awaitingShutdownTx (channel, message, state) {
219-
if (message.action === 'sign' && message.tag === 'shutdown_sign') {
220-
const signedTx = await Promise.resolve(state.sign(message.payload.tx))
221-
send(channel, { action: message.tag, payload: { tx: signedTx } })
224+
if (message.method === 'channels.sign.shutdown_sign') {
225+
const signedTx = await Promise.resolve(state.sign(message.params.data.tx))
226+
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown_sign', params: { tx: signedTx } })
222227
return { handler: awaitingShutdownOnChainTx, state }
223228
}
224229
}
225230

226231
export function awaitingShutdownOnChainTx (channel, message, state) {
227-
if (message.action === 'on_chain_tx') {
228-
state.resolveShutdownPromise(message.payload.tx)
232+
if (message.method === 'channels.on_chain_tx') {
233+
state.resolveShutdownPromise(message.params.data.tx)
229234
return { handler: channelClosed }
230235
}
231236
}
232237

233238
export function awaitingLeave (channel, message, state) {
234-
state.resolve({ channelId: message.channel_id, state: message.payload.state })
235-
return { handler: channelClosed }
239+
if (message.method === 'channels.leave') {
240+
state.resolve({ channelId: message.params.channel_id, state: message.params.data.state })
241+
return { handler: channelClosed }
242+
}
243+
if (message.method === 'channels.error') {
244+
state.reject(new Error(message.data.message))
245+
return { handler: channelOpen }
246+
}
236247
}
237248

238249
export function channelClosed (channel, message, state) {

0 commit comments

Comments
 (0)