Skip to content

Commit ef2ea62

Browse files
authored
Merge pull request #490 from aeternity/release/4.0.1
Release 4.0.1
2 parents 3dcf6e7 + f0b4e25 commit ef2ea62

File tree

16 files changed

+454
-74
lines changed

16 files changed

+454
-74
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1+
## [4.0.1](https://github.com/aeternity/aepp-sdk-js/compare/2.4.0...4.0.1) (2019-06-13)
2+
3+
4+
### Bug Fixes
5+
6+
* **RPC:** Add contract contractDecodeCallResultAPI to RPC ([#482](https://github.com/aeternity/aepp-sdk-js/issues/482)) ([7eb6bd8](https://github.com/aeternity/aepp-sdk-js/commit/7eb6bd8))
7+
* **README:** Fix flavor link ([#480](https://github.com/aeternity/aepp-sdk-js/pull/480))
8+
9+
### Code Refactoring
10+
11+
* **Compiler:** Fix compiler compatibility mechanism ([#479](https://github.com/aeternity/aepp-sdk-js/issues/479)) ([78cc990](https://github.com/aeternity/aepp-sdk-js/commit/78cc990))
12+
* **Utils:** Move json-bigint implementation to `utils` ([#486](https://github.com/aeternity/aepp-sdk-js/issues/486)) ([1538867](https://github.com/aeternity/aepp-sdk-js/commit/1538867))
13+
14+
### Build
15+
16+
* **webpack:** Add another bundle(`dist/aepp-sdk.browser-script.js`) for using in `<script>` tag ([#485](https://github.com/aeternity/aepp-sdk-js/pull/485))
17+
18+
19+
120
# [4.0.0](https://github.com/aeternity/aepp-sdk-js/compare/3.4.1...4.0.0) (2019-06-12)
221

22+
323
### Bug Fixes
424

525
* **Ae:** Fix exception when it used without Contract stamp

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ npm i https://github.com/aeternity/aepp-sdk-js#develop
5858

5959
### 2. Import (a chosen Flavor)
6060

61-
Import the right [flavor](docs/usage.md). For this example with get the `Universal` flavor, which contains all the features of the SDK:
61+
Import the right [flavor](docs/README.md#flavors--entry-points). For this example with get the `Universal` flavor, which contains all the features of the SDK:
6262

6363
```js
6464
import Ae from '@aeternity/aepp-sdk/es/ae/universal' // or other flavor

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ There are three different ways of incorporating aepp-sdk-js into your project, d
55
* ES Modules at `es/` (recommended)
66
* Node.js bundle at `dist/aepp-sdk.js`
77
* Browser bundle at `dist/aepp-sdk.browser.js`
8+
* Browser bundle for using through \<script\> tag at `dist/aepp-sdk.browser-script.js`
89

910
Also, please be aware that using `require` instead of module loader syntax
1011
(`import`) means that the default export automatically becomes exposed as

docs/api/contract.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
## @aeternity/aepp-sdk/es/contract
44
Contract Base module
55

6-
**Export**: Contract
76
**Example**
87
```js
98
import ContractBase from '@aeternity/aepp-sdk/es/contract'
@@ -13,6 +12,7 @@ import ContractBase from '@aeternity/aepp-sdk/es/contract'
1312
* [ContractBase([options])](#exp_module_@aeternity/aepp-sdk/es/contract--ContractBase)`Object`
1413
* *[.contractEncodeCallDataAPI(source, name, args)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractEncodeCallDataAPI)`String`*
1514
* *[.contractDecodeDataAPI(type, data)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeDataAPI)`String`*
15+
* *[.contractDecodeCallResultAPI(source, fn, callValue, callResult)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallResultAPI)`String`*
1616
* *[.contractDecodeCallDataBySourceAPI(source, function, callData)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallDataBySourceAPI)`String`*
1717
* *[.contractDecodeCallDataByCodeAPI(code, callData)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallDataByCodeAPI)`String`*
1818
* *[.compileContractAPI(code, [options])](#module_@aeternity/aepp-sdk/es/contract--ContractBase+compileContractAPI)`Object`*
@@ -67,6 +67,23 @@ Decode data
6767
| type | `String` | Contract call result type |
6868
| data | `String` | Encoded contract call result |
6969

70+
<a id="module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallResultAPI"></a>
71+
72+
#### *contractBase.contractDecodeCallResultAPI(source, fn, callValue, callResult) ⇒ `String`*
73+
Decode contract call result data
74+
75+
**Kind**: instance abstract method of [`ContractBase`](#exp_module_@aeternity/aepp-sdk/es/contract--ContractBase)
76+
**Returns**: `String` - - Decoded contract call result
77+
**Category**: async
78+
**rtype**: `(source: String, fn: String, callValue: String, callResult: String) => decodedResult: Promise[String]`
79+
80+
| Param | Type | Description |
81+
| --- | --- | --- |
82+
| source | `String` | Contract source |
83+
| fn | `String` | Fn name |
84+
| callValue | `String` | result data (cb_das...) |
85+
| callResult | `String` | contract call result status('ok', 'revert', ...) |
86+
7087
<a id="module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallDataBySourceAPI"></a>
7188

7289
#### *contractBase.contractDecodeCallDataBySourceAPI(source, function, callData) ⇒ `String`*

docs/guides/import-script-tag.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ The bundle will assign the SDK to a global `var` called `Ae`.
1515
<meta charset="utf-8">
1616
</head>
1717
<body>
18-
<script src="aepp-sdk.browser.js"></script>
18+
<script src="aepp-sdk.browser-script.js"></script>
1919
<script type="text/javascript">
20-
Ae.Wallet.default().then(ae => {
20+
Ae.Wallet().then(ae => {
2121
ae.height().then(height => {
2222
console.log('Current Block', height)
2323
})

es/contract/compiler.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import Http from '../utils/http'
2828
import ContractBase from './index'
2929
import semverSatisfies from '../utils/semver-satisfies'
30+
import AsyncInit from '../utils/async-init'
3031

3132
async function getCompilerVersion (options = {}) {
3233
return this.http
@@ -35,43 +36,68 @@ async function getCompilerVersion (options = {}) {
3536
}
3637

3738
async function contractEncodeCallDataAPI (source, name, args = [], options = {}) {
39+
this.isInit()
3840
return this.http
3941
.post('/encode-calldata', { source, 'function': name, arguments: args }, options)
4042
.then(({ calldata }) => calldata)
4143
}
4244

4345
async function contractDecodeCallDataByCodeAPI (bytecode, calldata, options = {}) {
46+
this.isInit()
4447
return this.http
4548
.post('/decode-calldata/bytecode', { bytecode, calldata }, options)
4649
}
4750

4851
async function contractDecodeCallDataBySourceAPI (source, fn, callData, options = {}) {
52+
this.isInit()
4953
return this.http
5054
.post('/decode-calldata/source', { 'function': fn, source, calldata: callData }, options)
5155
}
5256

5357
async function contractDecodeCallResultAPI (source, fn, callValue, callResult, options = {}) {
58+
this.isInit()
5459
return this.http
5560
.post('/decode-call-result', { 'function': fn, source, 'call-result': callResult, 'call-value': callValue }, options)
5661
}
5762

5863
async function contractDecodeDataAPI (type, data, options = {}) {
64+
this.isInit()
5965
return this.http
6066
.post('/decode-data', { data, 'sophia-type': type }, options)
6167
.then(({ data }) => data)
6268
}
6369

6470
async function compileContractAPI (code, options = {}) {
71+
this.isInit()
6572
return this.http.post('/compile', { code, options }, options)
6673
.then(({ bytecode }) => bytecode)
6774
}
6875

6976
async function contractGetACI (code, options = {}) {
77+
this.isInit()
7078
return this.http.post('/aci', { code, options }, options)
7179
}
7280

73-
function setCompilerUrl (url) {
81+
async function setCompilerUrl (url) {
7482
this.http.changeBaseUrl(url)
83+
this.compilerVersion = null
84+
await this.checkCompatibility()
85+
}
86+
87+
async function checkCompatibility (force = false) {
88+
this.compilerVersion = await this.getCompilerVersion().catch(e => null)
89+
if (!this.compilerVersion && !force) throw new Error('Compiler do not respond')
90+
if (this.compilerVersion && !semverSatisfies(this.compilerVersion.split('-')[0], COMPILER_GE_VERSION, COMPILER_LT_VERSION)) {
91+
const version = this.compilerVersion
92+
this.compilerVersion = null
93+
throw new Error(`Unsupported compiler version ${version}. ` +
94+
`Supported: >= ${COMPILER_GE_VERSION} < ${COMPILER_LT_VERSION}`)
95+
}
96+
}
97+
98+
function isInit () {
99+
if (this.compilerVersion === null) throw Error('Compiler not defined')
100+
return true
75101
}
76102

77103
/**
@@ -86,14 +112,10 @@ function setCompilerUrl (url) {
86112
* @return {Object} Contract compiler instance
87113
* @example ContractCompilerAPI({ compilerUrl: 'COMPILER_URL' })
88114
*/
89-
const ContractCompilerAPI = ContractBase.compose({
115+
const ContractCompilerAPI = AsyncInit.compose(ContractBase, {
90116
async init ({ compilerUrl = this.compilerUrl }) {
91117
this.http = Http({ baseUrl: compilerUrl })
92-
this.compilerVersion = await this.getCompilerVersion()
93-
if (!semverSatisfies(this.compilerVersion.split('-')[0], COMPILER_GE_VERSION, COMPILER_LT_VERSION)) {
94-
throw new Error(`Unsupported compiler version ${this.compilerVersion}. ` +
95-
`Supported: >= ${COMPILER_GE_VERSION} < ${COMPILER_LT_VERSION}`)
96-
}
118+
await this.checkCompatibility(true)
97119
},
98120
methods: {
99121
contractEncodeCallDataAPI,
@@ -104,7 +126,9 @@ const ContractCompilerAPI = ContractBase.compose({
104126
contractDecodeCallDataBySourceAPI,
105127
contractDecodeCallResultAPI,
106128
setCompilerUrl,
107-
getCompilerVersion
129+
getCompilerVersion,
130+
isInit,
131+
checkCompatibility
108132
},
109133
props: {
110134
compilerVersion: null

es/contract/index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const ContractBase = stampit({
4848
'contractDecodeCallDataByCodeAPI',
4949
'contractGetACI',
5050
'setCompilerUrl',
51-
'getCompilerVersion'
51+
'getCompilerVersion',
52+
'contractDecodeCallResultAPI'
5253
]
5354
}
5455
}
@@ -59,7 +60,8 @@ const ContractBase = stampit({
5960
compileContractAPI: required,
6061
contractGetACI: required,
6162
setCompilerUrl: required,
62-
getCompilerVersion: required
63+
getCompilerVersion: required,
64+
contractDecodeCallResultAPI: required
6365
}
6466
}))
6567

@@ -88,6 +90,20 @@ const ContractBase = stampit({
8890
* @return {String} - Decoded contract call result
8991
*/
9092

93+
/**
94+
* Decode contract call result data
95+
* @function contractDecodeCallResultAPI
96+
* @instance
97+
* @abstract
98+
* @category async
99+
* @rtype (source: String, fn: String, callValue: String, callResult: String) => decodedResult: Promise[String]
100+
* @param {String} source - Contract source
101+
* @param {String} fn - Fn name
102+
* @param {String} callValue - result data (cb_das...)
103+
* @param {String} callResult - contract call result status('ok', 'revert', ...)
104+
* @return {String} - Decoded contract call result
105+
*/
106+
91107
/**
92108
* Decode call data by source
93109
* @function contractDecodeCallDataBySourceAPI

es/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function axiosError (handler) {
102102
*/
103103
const Node = stampit({
104104
async init ({ url = this.url, internalUrl = this.internalUrl, axiosConfig: { config, errorHandler } = {} }) {
105+
if (!url || !internalUrl) throw new Error('"url" and "internalUrl" required')
105106
url = url.replace(/\/?$/, '')
106107
internalUrl = internalUrl.replace(/\/?$/, '')
107108
// Get swagger schema

es/utils/http.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from 'axios'
2-
import JSONbig from 'json-bigint'
2+
import JsonBig from './json-big'
33
import * as R from 'ramda'
44
import stampit from '@stamp/it'
55

@@ -59,7 +59,7 @@ const Http = stampit({
5959
headers: { 'Content-Type': 'application/json' },
6060
transformResponse: [(data) => {
6161
try {
62-
return JSONbig({ 'storeAsString': true }).parse(data)
62+
return JsonBig.parse(data)
6363
} catch (e) {
6464
return data
6565
}

0 commit comments

Comments
 (0)