Skip to content

Commit

Permalink
Merge pull request #143 from aeternity/release/0.9.2
Browse files Browse the repository at this point in the history
Release/0.9.2
  • Loading branch information
shekhar-shubhendu authored Aug 22, 2019
2 parents 8612e17 + a1a26cc commit a88684e
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aepp-middleware"
version = "0.9.1"
version = "0.9.2"
authors = ["John Newby <@johnsnewby>", "Shubhendu Shekhar <@shekhar-shubhendu>", "Andrea Giacobino <@noandrea>" ]

[lib]
Expand Down
5 changes: 5 additions & 0 deletions frontend/assets/sprite/svg/ae-loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/components/searchBar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
>
<button
class="search-bar-button"
@click="processInput"
>
<AppIcon name="search" />
</button>
Expand Down
4 changes: 3 additions & 1 deletion frontend/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ module.exports = {
middlewareURL: process.env.NUXT_APP_NODE_URL || 'https://testnet.mdw.aepps.com',
middlewareWS: process.env.NUXT_APP_NODE_WS || 'wss://testnet.mdw.aepps.com/websocket',
networkName: process.env.NUXT_APP_NETWORK_NAME || 'TEST NET',
swaggerHub: process.env.NUXT_APP_SWAGGER_HUB || 'https://app.swaggerhub.com/apis-docs/sshekhar/aepp-middleware/1.0'
swaggerHub: process.env.NUXT_APP_SWAGGER_HUB || 'https://app.swaggerhub.com/apis-docs/sshekhar/aepp-middleware/1.0',
faucetNetwork: process.env.NUXT_APP_FAUCET_NETWORK || 'ae_uat',
faucetAPI: process.env.NUXT_APP_FAUCET_API || 'https://testnet.faucet.aepps.com/account'
},
/*
** Plugins to load before mounting the App
Expand Down
213 changes: 213 additions & 0 deletions frontend/pages/faucet/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<template>
<div>
<PageHeader
title="Faucet"
:has-crumbs="true"
:page="{to: '/faucet', name: 'Testnet Faucet'}"
/>
<div class="faucet-bar">
<input
v-model="userAddress"
:placeholder="placeholder"
class="faucet-bar-input"
type="text"
@keyup.enter="processInput"
>
<button
class="faucet-bar-button"
@click="processInput"
>
<AppIcon name="left-more" />
</button>
</div>
<div class="faucet-bar-messages">
<AppIcon
v-if="loading"
name="ae-loader"
/>
<AppTableBody>
<AppTableRow
v-if="tx_hash"
extend
>
<AppTableCell extend>
<nuxt-link
:to="`/account/transactions/${account}`"
>
<AppDefinition
type="list"
title="Account"
>
{{ account }}
</AppDefinition>
</nuxt-link>
</AppTableCell>
</AppTableRow>
</AppTableBody>
<AppTableBody>
<AppTableRow
v-if="tx_hash"
extend
>
<AppTableCell extend>
<nuxt-link
:to="`/transactions/${tx_hash}`"
>
<AppDefinition
type="list"
title="Hash"
>
{{ tx_hash }}
</AppDefinition>
</nuxt-link>
</AppTableCell>
</AppTableRow>
</AppTableBody>
<AppTableBody>
<AppTableRow
v-if="tx_hash"
extend
>
<AppTableCell extend>
<AppDefinition
type="list"
title="Balance"
>
{{ balance | prefixAmount }}
</AppDefinition>
</AppTableCell>
</AppTableRow>
</AppTableBody>
<AppTableBody>
<AppTableRow
v-if="errorMessage"
extend
>
<AppTableCell extend>
<AppDefinition
type="list"
title="Message"
>
{{ errorMessage }}
</AppDefinition>
</AppTableCell>
</AppTableRow>
</AppTableBody>
</div>
</div>
</template>
<script>
import AppIcon from '../../components/appIcon'
import PageHeader from '../../components/PageHeader'
import AppDefinition from '../../components/appDefinition'
import AppTableBody from '../../components/appTableBody'
import AppTableRow from '../../components/appTableRow'
import AppTableCell from '../../components/appTableCell'
import prefixAmount from '../../plugins/filters/prefixedAmount'
export default {
name: 'Faucet',
components: {
AppIcon,
PageHeader,
AppDefinition,
AppTableBody,
AppTableRow,
AppTableCell
},
filters: {
prefixAmount
},
props: {
placeholder: {
type: String,
default: 'ak_YOUrPubl1ckeyh4sHh3r3'
}
},
data () {
return {
userAddress: '',
account: '',
balance: 0,
tx_hash: '',
errorMessage: '',
loading: false
}
},
beforeMount () {
if (this.$store.state.faucetNetwork !== this.$store.state.status.network_id) {
this.$router.push('/')
}
},
mounted () {
this.resetData()
},
methods: {
async processInput () {
this.resetData()
if (this.userAddress.match(/^ak_[1-9A-HJ-NP-Za-km-z]{48,50}$/)) {
this.account = this.userAddress
this.loading = true
const result = await this.$store.dispatch('account/createFaucetTx', this.userAddress)
this.loading = false
if (result.error) {
this.errorMessage = result.error
} else {
this.balance = result.balance
this.tx_hash = result.tx_hash
}
this.userAddress = ''
}
},
resetData () {
this.account = ''
this.balance = 0
this.tx_hash = ''
this.errorMessage = ''
}
}
}
</script>
<style scoped lang="scss">
@import "~@aeternity/aepp-components-3/src/styles/variables/colors";
@import "~@aeternity/aepp-components-3/src/styles/placeholders/typography";
.faucet-bar {
position: relative;
width: 100%;
display: flex;
flex-direction: row;
background-color: #FFFFFF;
border-radius: .4rem;
overflow: hidden;
justify-content: center;
align-items: center;
&-input {
width: 100%;
border: none;
padding: 1.3rem .6rem;
color: $color-neutral-negative-1;
@extend %face-sans-base;
}
&-button {
border: none;
background-color: transparent;
cursor: pointer;
justify-content: center;
align-items: center;
line-height: 0;
padding: 1.3rem .6rem;
font-size: 1.5rem;
color: $color-neutral-negative-1;
}
&-messages {
margin-top: 2rem;
.app-icon {
width: 8rem;
height: 10rem;
margin-left: 30rem;
}
}
}
</style>
11 changes: 11 additions & 0 deletions frontend/partials/appMainNav/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
>
Swagger Hub
</AppNavLink>
<AppNavLink
v-if="isFaucetActive"
to="/faucet"
>
Faucet
</AppNavLink>
</AppNav>
</AppNavAccordion>
</div>
Expand All @@ -66,6 +72,11 @@ export default {
AppNavLink,
SearchBar,
Logo
},
computed: {
isFaucetActive () {
return this.$store.state.faucetNetwork === this.$store.state.status.network_id
}
}
}
</script>
Expand Down
22 changes: 22 additions & 0 deletions frontend/store/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,27 @@ export const actions = {
}
return basicError
}
},

createFaucetTx: async function ({ rootState: { faucetApi }, commit }, account) {
try {
const url = `${faucetApi}/${account}`
const acc = await axios.post(url)
console.info('MDW 🔗 ' + url)
return acc.data
} catch (e) {
commit('catchError', 'Error', {
root: true
})
const basicError = {
id: account,
balance: 0,
error: 'Unable to fetch account details'
}
if (e.response.status === 425) {
basicError.error = e.response.data.message
}
return basicError
}
}
}
13 changes: 8 additions & 5 deletions frontend/store/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import axios from 'axios'

export const state = () => ({
$nodeStatus: {},
nodeStatus: {},
nodeUrl: process.env.middlewareURL,
wsUrl: process.env.middlewareWS,
networkName: process.env.networkName,
swaggerHub: process.env.swaggerHub,
faucetNetwork: process.env.faucetNetwork,
faucetApi: process.env.faucetAPI,
error: '',
height: 0,
status: {},
Expand Down Expand Up @@ -43,10 +45,10 @@ export const mutations = {
/**
* setNodeStatus
* @param {Object} state
* @param $nodeStatus
* @param nodeStatus
*/
setNodeStatus (state, $nodeStatus) {
Object.assign(state, { $nodeStatus })
setNodeStatus (state, nodeStatus) {
Object.assign(state, { nodeStatus })
},
/**
* changeNetwork
Expand Down Expand Up @@ -105,7 +107,7 @@ export const actions = {
},
async status ({ rootState: { nodeUrl }, commit }) {
try {
const url = `${nodeUrl}/middleware/status`
const url = `${nodeUrl}/v2/status`
const status = (await axios.get(url)).data
console.info('MDW 🔗 ' + url)
commit('setStatus', status)
Expand All @@ -132,6 +134,7 @@ export const actions = {
}
},
async nuxtServerInit ({ dispatch }, { context }) {
dispatch('status')
await dispatch('height')
await Promise.all([
dispatch('generations/nuxtServerInit', context),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![feature(custom_attribute)]
#![feature(proc_macro_hygiene, decl_macro)]
#![feature(try_trait)]
#![feature(try_from)]
extern crate backtrace;
extern crate base58;
extern crate base58check;
Expand Down
14 changes: 10 additions & 4 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ impl BlockLoader {
let conn = PGCONNECTION.get()?;
let mut fork_was_detected = false;
let chain_length = KeyBlock::top_height(&conn)?;
let current_height = chain_length;

let mut current_height = chain_length;
let mut blocks_since_last_fork = 0;
loop {
let mut in_fork = false;
let gen_from_db: JsonGeneration = match JsonGeneration::get_generation_at_height(
Expand Down Expand Up @@ -221,9 +221,13 @@ impl BlockLoader {
}

if !in_fork {
debug!("No fork found. Exiting loop");
break;
blocks_since_last_fork += 1;
if blocks_since_last_fork >= 5 {
debug!("No fork found. Exiting loop");
break;
}
} else {
blocks_since_last_fork = 0;
BlockLoader::invalidate_block_at_height(current_height, &conn, &_tx)?;
info!(
"{} detected at height {} with chain length {}\n\
Expand All @@ -240,6 +244,8 @@ impl BlockLoader {
gen_from_server
);
}
current_height -= 1;
thread::sleep(std::time::Duration::new(blocks_since_last_fork+1, 0));
}
Ok(fork_was_detected)
}
Expand Down
Loading

0 comments on commit a88684e

Please sign in to comment.