Skip to content

Commit

Permalink
feat(Aepp): Add Compiler to Aepp rpc methods. Update example app (#312)
Browse files Browse the repository at this point in the history
* feat(Aepp): Add Compiler to Aepp rpc methods. Update example app

* fix(Account): Move address formatter to MemoryAccount due to rpc issue

* force Jenkins

* fix(Crypto): Fix crypto `formatAddress`

* fix(Crypto): Move ADDRESS_FORMAT to crypto

* fix(Account): Fix imports
  • Loading branch information
nduchak committed Apr 9, 2019
1 parent 68ae9e1 commit 9c72521
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 32 deletions.
10 changes: 0 additions & 10 deletions es/account/index.js
Expand Up @@ -30,11 +30,6 @@ import { TX_TYPE } from '../tx/builder/schema'

const DEFAULT_NETWORK_ID = `ae_mainnet`

export const ADDRESS_FORMAT = {
sophia: 1,
api: 2,
raw: 3
}
/**
* Sign encoded transaction
* @instance
Expand Down Expand Up @@ -74,11 +69,6 @@ const Account = stampit({
if (!this.networkId && networkId) {
this.networkId = networkId
}
// Add address formatter
this.getAddress = this.address
this.address = async function (format) {
return Crypto.formatAddress(format, await this.getAddress())
}
},
methods: { signTransaction },
deepConf: {
Expand Down
4 changes: 2 additions & 2 deletions es/account/memory.js
Expand Up @@ -31,8 +31,8 @@ async function sign (data) {
return Promise.resolve(Crypto.sign(data, secrets.get(this).secretKey))
}

async function address () {
return Promise.resolve(secrets.get(this).publicKey)
async function address (format = Crypto.ADDRESS_FORMAT.api) {
return Promise.resolve(Crypto.formatAddress(format, secrets.get(this).publicKey))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion es/ae/aepp.js
Expand Up @@ -24,7 +24,7 @@

import Ae from './'
import Aens from './aens'
import Contract from './contract'
import { Contract } from './contract'
import Rpc from '../rpc/client'

/**
Expand Down
7 changes: 5 additions & 2 deletions es/ae/contract.js
Expand Up @@ -32,6 +32,7 @@ import * as R from 'ramda'
import { isBase64 } from '../utils/crypto'
import ContractCompilerAPI from '../contract/compiler'
import ContractACI from '../contract/aci'
import ContractBase from '../contract'

/**
* Handle contract call error
Expand Down Expand Up @@ -228,7 +229,7 @@ async function contractCompile (source, options = {}) {
* @param {Object} [options={}] - Initializer object
* @return {Object} Contract instance
*/
const Contract = Ae.compose(ContractACI, ContractCompilerAPI, {
export const Contract = Ae.compose(ContractBase, ContractACI, {
methods: {
contractCompile,
contractCallStatic,
Expand All @@ -252,4 +253,6 @@ const Contract = Ae.compose(ContractACI, ContractCompilerAPI, {
}
})

export default Contract
export const ContractWithCompiler = Contract.compose(ContractCompilerAPI)

export default ContractWithCompiler
6 changes: 4 additions & 2 deletions es/contract/index.js
Expand Up @@ -43,15 +43,17 @@ const ContractBase = stampit({
methods: [
'contractEncodeCallDataAPI',
'contractDecodeDataAPI',
'compileContractAPI'
'compileContractAPI',
'contractGetACI'
]
}
}
}, required({
methods: {
contractEncodeCallDataAPI: required,
contractDecodeDataAPI: required,
compileContractAPI: required
compileContractAPI: required,
contractGetACI: required
}
}))

Expand Down
7 changes: 6 additions & 1 deletion es/utils/crypto.js
Expand Up @@ -28,7 +28,6 @@ import nacl from 'tweetnacl'
import aesjs from 'aes-js'
import { leftPad, rightPad, toBytes } from './bytes'
import shajs from 'sha.js'
import { ADDRESS_FORMAT } from '../account'
import { decode as decodeNode } from '../tx/builder/helpers'

const Ecb = aesjs.ModeOfOperation.ecb
Expand All @@ -46,6 +45,12 @@ export function isBase64 (str) {
return !!(index === -1 || str.slice(index).match(/={1,2}/))
}

export const ADDRESS_FORMAT = {
sophia: 1,
api: 2,
raw: 3
}

/**
* Format account address
* @rtype (format: String, address: String) => tx: Promise[String]
Expand Down
1 change: 0 additions & 1 deletion es/utils/http.js
Expand Up @@ -52,7 +52,6 @@ const processResponse = async (res) => {

const Http = stampit({
init ({ baseUrl }) {
if (!baseUrl) console.warn('You need to provider base url.')
this.baseUrl = baseUrl
},
methods: {
Expand Down
16 changes: 5 additions & 11 deletions examples/connect-two-ae/aepp/src/components/Home.vue
Expand Up @@ -114,7 +114,7 @@ export default {
type state = ()
function main(x : int) = x`,
byteCode: null,
contractInitState: '()',
contractInitState: [],
deployInfo: null
}
},
Expand All @@ -134,19 +134,19 @@ export default {
async deploy (code, options = {}) {
console.log(`Deploying contract...`)
try {
return await this.client.contractDeploy(this.byteCode, this.abi, { initState: this.contractInitState, options })
return await this.client.contractDeploy(this.byteCode, this.contractCode, this.contractInitState, options)
} catch (err) {
this.deployErr = err
console.error(err)
}
},
async call (code, abi, contractAddress, method = 'main', returnType = 'int', args = '(5)', options = {}) {
async call (code, abi, contractAddress, method = 'main', returnType = 'int', args = ['5'], options = {}) {
console.log(`Deploying contract...`)
try {
const { result } = await this.client.contractCall(this.byteCode, this.abi, this.deployInfo.address, method, { args: args, options })
const result = await this.client.contractCall(this.contractCode, this.deployInfo.address, method, args, options)
return Object.assign(
result,
{ decodedRes: await this.client.contractDecodeData(returnType, result.returnValue) }
{ decodedRes: await result.decode(returnType) }
)
} catch (err) {
this.deployErr = err
Expand Down Expand Up @@ -181,12 +181,6 @@ export default {
this.pub = address
})
.catch(e => { this.pub = `Rejected: ${e}` })
// // AENS
// ae.aensPreclaim(`test${Math.floor(Math.random() * 101)}.test`)
// .then(name => { return name.claim() })
// .then(name => { return name.update('ak_bAxmQLxXv8UnVEKfHpvDwp8qEsrVE3tnezBffLdtVMVKP6GC2') })
// .then(name => { return name.revoke() })
// .catch(e => {debugger})
})
}
}
Expand Down
6 changes: 4 additions & 2 deletions examples/connect-two-ae/identity/src/components/Home.vue
Expand Up @@ -54,8 +54,9 @@ export default {
wallet: null,
balance: null,
height: null,
url: 'https://sdk-mainnet.aepps.com',
internalUrl: 'https://sdk-mainnet.aepps.com',
url: 'http://localhost:3013',
internalUrl: 'http://localhost:3113',
compilerUrl: 'https://compiler.aepps.com',
aeppUrl: '//0.0.0.0:9001'
}
},
Expand All @@ -73,6 +74,7 @@ export default {
Wallet({
url: this.url,
internalUrl: this.internalUrl,
compilerUrl: this.compilerUrl,
accounts: [MemoryAccount({keypair: {secretKey: this.priv, publicKey: this.pub}})],
address: this.pub,
onTx: this.confirmDialog,
Expand Down
1 change: 1 addition & 0 deletions test/integration/index.js
Expand Up @@ -14,6 +14,7 @@
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/

import Ae from '../../es/ae/universal'
import * as Crypto from '../../es/utils/crypto'
import { BigNumber } from 'bignumber.js'
Expand Down

0 comments on commit 9c72521

Please sign in to comment.