Skip to content

Commit

Permalink
Merge pull request #490 from aeternity/release/4.0.1
Browse files Browse the repository at this point in the history
Release 4.0.1
  • Loading branch information
nduchak authored Jun 14, 2019
2 parents 3dcf6e7 + f0b4e25 commit ef2ea62
Show file tree
Hide file tree
Showing 16 changed files with 454 additions and 74 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
## [4.0.1](https://github.com/aeternity/aepp-sdk-js/compare/2.4.0...4.0.1) (2019-06-13)


### Bug Fixes

* **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))
* **README:** Fix flavor link ([#480](https://github.com/aeternity/aepp-sdk-js/pull/480))

### Code Refactoring

* **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))
* **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))

### Build

* **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))



# [4.0.0](https://github.com/aeternity/aepp-sdk-js/compare/3.4.1...4.0.0) (2019-06-12)


### Bug Fixes

* **Ae:** Fix exception when it used without Contract stamp
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ npm i https://github.com/aeternity/aepp-sdk-js#develop

### 2. Import (a chosen Flavor)

Import the right [flavor](docs/usage.md). For this example with get the `Universal` flavor, which contains all the features of the SDK:
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:

```js
import Ae from '@aeternity/aepp-sdk/es/ae/universal' // or other flavor
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ There are three different ways of incorporating aepp-sdk-js into your project, d
* ES Modules at `es/` (recommended)
* Node.js bundle at `dist/aepp-sdk.js`
* Browser bundle at `dist/aepp-sdk.browser.js`
* Browser bundle for using through \<script\> tag at `dist/aepp-sdk.browser-script.js`

Also, please be aware that using `require` instead of module loader syntax
(`import`) means that the default export automatically becomes exposed as
Expand Down
19 changes: 18 additions & 1 deletion docs/api/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## @aeternity/aepp-sdk/es/contract
Contract Base module

**Export**: Contract
**Example**
```js
import ContractBase from '@aeternity/aepp-sdk/es/contract'
Expand All @@ -13,6 +12,7 @@ import ContractBase from '@aeternity/aepp-sdk/es/contract'
* [ContractBase([options])](#exp_module_@aeternity/aepp-sdk/es/contract--ContractBase)`Object`
* *[.contractEncodeCallDataAPI(source, name, args)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractEncodeCallDataAPI)`String`*
* *[.contractDecodeDataAPI(type, data)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeDataAPI)`String`*
* *[.contractDecodeCallResultAPI(source, fn, callValue, callResult)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallResultAPI)`String`*
* *[.contractDecodeCallDataBySourceAPI(source, function, callData)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallDataBySourceAPI)`String`*
* *[.contractDecodeCallDataByCodeAPI(code, callData)](#module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallDataByCodeAPI)`String`*
* *[.compileContractAPI(code, [options])](#module_@aeternity/aepp-sdk/es/contract--ContractBase+compileContractAPI)`Object`*
Expand Down Expand Up @@ -67,6 +67,23 @@ Decode data
| type | `String` | Contract call result type |
| data | `String` | Encoded contract call result |

<a id="module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallResultAPI"></a>

#### *contractBase.contractDecodeCallResultAPI(source, fn, callValue, callResult) ⇒ `String`*
Decode contract call result data

**Kind**: instance abstract method of [`ContractBase`](#exp_module_@aeternity/aepp-sdk/es/contract--ContractBase)
**Returns**: `String` - - Decoded contract call result
**Category**: async
**rtype**: `(source: String, fn: String, callValue: String, callResult: String) => decodedResult: Promise[String]`

| Param | Type | Description |
| --- | --- | --- |
| source | `String` | Contract source |
| fn | `String` | Fn name |
| callValue | `String` | result data (cb_das...) |
| callResult | `String` | contract call result status('ok', 'revert', ...) |

<a id="module_@aeternity/aepp-sdk/es/contract--ContractBase+contractDecodeCallDataBySourceAPI"></a>

#### *contractBase.contractDecodeCallDataBySourceAPI(source, function, callData) ⇒ `String`*
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/import-script-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The bundle will assign the SDK to a global `var` called `Ae`.
<meta charset="utf-8">
</head>
<body>
<script src="aepp-sdk.browser.js"></script>
<script src="aepp-sdk.browser-script.js"></script>
<script type="text/javascript">
Ae.Wallet.default().then(ae => {
Ae.Wallet().then(ae => {
ae.height().then(height => {
console.log('Current Block', height)
})
Expand Down
40 changes: 32 additions & 8 deletions es/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import Http from '../utils/http'
import ContractBase from './index'
import semverSatisfies from '../utils/semver-satisfies'
import AsyncInit from '../utils/async-init'

async function getCompilerVersion (options = {}) {
return this.http
Expand All @@ -35,43 +36,68 @@ async function getCompilerVersion (options = {}) {
}

async function contractEncodeCallDataAPI (source, name, args = [], options = {}) {
this.isInit()
return this.http
.post('/encode-calldata', { source, 'function': name, arguments: args }, options)
.then(({ calldata }) => calldata)
}

async function contractDecodeCallDataByCodeAPI (bytecode, calldata, options = {}) {
this.isInit()
return this.http
.post('/decode-calldata/bytecode', { bytecode, calldata }, options)
}

async function contractDecodeCallDataBySourceAPI (source, fn, callData, options = {}) {
this.isInit()
return this.http
.post('/decode-calldata/source', { 'function': fn, source, calldata: callData }, options)
}

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

async function contractDecodeDataAPI (type, data, options = {}) {
this.isInit()
return this.http
.post('/decode-data', { data, 'sophia-type': type }, options)
.then(({ data }) => data)
}

async function compileContractAPI (code, options = {}) {
this.isInit()
return this.http.post('/compile', { code, options }, options)
.then(({ bytecode }) => bytecode)
}

async function contractGetACI (code, options = {}) {
this.isInit()
return this.http.post('/aci', { code, options }, options)
}

function setCompilerUrl (url) {
async function setCompilerUrl (url) {
this.http.changeBaseUrl(url)
this.compilerVersion = null
await this.checkCompatibility()
}

async function checkCompatibility (force = false) {
this.compilerVersion = await this.getCompilerVersion().catch(e => null)
if (!this.compilerVersion && !force) throw new Error('Compiler do not respond')
if (this.compilerVersion && !semverSatisfies(this.compilerVersion.split('-')[0], COMPILER_GE_VERSION, COMPILER_LT_VERSION)) {
const version = this.compilerVersion
this.compilerVersion = null
throw new Error(`Unsupported compiler version ${version}. ` +
`Supported: >= ${COMPILER_GE_VERSION} < ${COMPILER_LT_VERSION}`)
}
}

function isInit () {
if (this.compilerVersion === null) throw Error('Compiler not defined')
return true
}

/**
Expand All @@ -86,14 +112,10 @@ function setCompilerUrl (url) {
* @return {Object} Contract compiler instance
* @example ContractCompilerAPI({ compilerUrl: 'COMPILER_URL' })
*/
const ContractCompilerAPI = ContractBase.compose({
const ContractCompilerAPI = AsyncInit.compose(ContractBase, {
async init ({ compilerUrl = this.compilerUrl }) {
this.http = Http({ baseUrl: compilerUrl })
this.compilerVersion = await this.getCompilerVersion()
if (!semverSatisfies(this.compilerVersion.split('-')[0], COMPILER_GE_VERSION, COMPILER_LT_VERSION)) {
throw new Error(`Unsupported compiler version ${this.compilerVersion}. ` +
`Supported: >= ${COMPILER_GE_VERSION} < ${COMPILER_LT_VERSION}`)
}
await this.checkCompatibility(true)
},
methods: {
contractEncodeCallDataAPI,
Expand All @@ -104,7 +126,9 @@ const ContractCompilerAPI = ContractBase.compose({
contractDecodeCallDataBySourceAPI,
contractDecodeCallResultAPI,
setCompilerUrl,
getCompilerVersion
getCompilerVersion,
isInit,
checkCompatibility
},
props: {
compilerVersion: null
Expand Down
20 changes: 18 additions & 2 deletions es/contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const ContractBase = stampit({
'contractDecodeCallDataByCodeAPI',
'contractGetACI',
'setCompilerUrl',
'getCompilerVersion'
'getCompilerVersion',
'contractDecodeCallResultAPI'
]
}
}
Expand All @@ -59,7 +60,8 @@ const ContractBase = stampit({
compileContractAPI: required,
contractGetACI: required,
setCompilerUrl: required,
getCompilerVersion: required
getCompilerVersion: required,
contractDecodeCallResultAPI: required
}
}))

Expand Down Expand Up @@ -88,6 +90,20 @@ const ContractBase = stampit({
* @return {String} - Decoded contract call result
*/

/**
* Decode contract call result data
* @function contractDecodeCallResultAPI
* @instance
* @abstract
* @category async
* @rtype (source: String, fn: String, callValue: String, callResult: String) => decodedResult: Promise[String]
* @param {String} source - Contract source
* @param {String} fn - Fn name
* @param {String} callValue - result data (cb_das...)
* @param {String} callResult - contract call result status('ok', 'revert', ...)
* @return {String} - Decoded contract call result
*/

/**
* Decode call data by source
* @function contractDecodeCallDataBySourceAPI
Expand Down
1 change: 1 addition & 0 deletions es/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function axiosError (handler) {
*/
const Node = stampit({
async init ({ url = this.url, internalUrl = this.internalUrl, axiosConfig: { config, errorHandler } = {} }) {
if (!url || !internalUrl) throw new Error('"url" and "internalUrl" required')
url = url.replace(/\/?$/, '')
internalUrl = internalUrl.replace(/\/?$/, '')
// Get swagger schema
Expand Down
4 changes: 2 additions & 2 deletions es/utils/http.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios'
import JSONbig from 'json-bigint'
import JsonBig from './json-big'
import * as R from 'ramda'
import stampit from '@stamp/it'

Expand Down Expand Up @@ -59,7 +59,7 @@ const Http = stampit({
headers: { 'Content-Type': 'application/json' },
transformResponse: [(data) => {
try {
return JSONbig({ 'storeAsString': true }).parse(data)
return JsonBig.parse(data)
} catch (e) {
return data
}
Expand Down
Loading

0 comments on commit ef2ea62

Please sign in to comment.