Skip to content

Commit

Permalink
number of confirmations is now a setting
Browse files Browse the repository at this point in the history
  • Loading branch information
julien51 committed Oct 9, 2018
1 parent 50406a1 commit d179e44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
13 changes: 9 additions & 4 deletions unlock-app/src/__tests__/helpers/Locks.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {getLockTransaction, getLockConfirmations, getLockStatusString} from '../../helpers/Locks'
import configure from '../../config'

const config = configure(global)

describe('lockHelpers', () => {
it ('should retrieve a transaction from a lock when a match exists', () => {
Expand Down Expand Up @@ -101,15 +104,16 @@ describe('lockHelpers', () => {

expect(getLockConfirmations(transactions, Lock.address)).toEqual(null)
})
it ('should return the status "deployed" for locks with mined transactions and at least 12 confirmations', () => {

it ('should return the status "deployed" for locks with mined transactions and at least the number of required confirmations', () => {
const Lock = {
address: '0x1234567890',
}
const transactions = {
all: {
theTransactionWereLookingFor: {
hash: 'theTransactionWereLookingFor',
confirmations: 12,
confirmations: config.requiredConfirmations,
status: 'mined',
lock: {
address: '0x1234567890',
Expand All @@ -120,15 +124,16 @@ describe('lockHelpers', () => {

expect(getLockStatusString(transactions, Lock.address)).toEqual('deployed')
})
it ('should return the status "confirming" for locks with mined transactions and under 12 confirmations', () => {

it ('should return the status "confirming" for locks with mined transactions and under the required number of confirmations', () => {
const Lock = {
address: '0x1234567890',
}
const transactions = {
all: {
theTransactionWereLookingFor: {
hash: 'theTransactionWereLookingFor',
confirmations: 4,
confirmations: config.requiredConfirmations-1,
status: 'mined',
lock: {
address: '0x1234567890',
Expand Down
5 changes: 5 additions & 0 deletions unlock-app/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function configure(environment) {
let providers = {}
let isRequiredNetwork = () => false
let requiredNetwork = 'Dev'
let requiredConfirmations = 12

if (env === 'dev') {
// In dev, we assume there is a running local ethereum node with unlocked accounts listening to the HTTP endpoint. We can add more providers (Websockets...) if needed.
Expand All @@ -64,6 +65,9 @@ export default function configure(environment) {

// In dev, the network can be anything above 100
isRequiredNetwork = (networkId) => networkId > 100

// In dev, we only require 0 confirmation because we only mine when there are pending transactions
requiredConfirmations = 0
}

if (env === 'staging') {
Expand Down Expand Up @@ -92,5 +96,6 @@ export default function configure(environment) {
providers,
isRequiredNetwork,
requiredNetwork,
requiredConfirmations,
}
}
8 changes: 6 additions & 2 deletions unlock-app/src/helpers/Locks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import configure from '../config'

const config = configure(global)

/**
* Given the address of a lock, returns its accompanying transaction
* @param transactionStore
Expand Down Expand Up @@ -36,7 +40,7 @@ export function getLockConfirmations(transactionStore, lockAddress) {
export function getLockStatusString(transactionStore, lockAddress) {
let transaction = getLockTransaction(transactionStore, lockAddress)
if (!transaction) return 'notfound'
if (transaction.status === 'mined' && transaction.confirmations >= 12) return 'deployed'
if (transaction.status === 'mined' && transaction.confirmations < 12) return 'confirming'
if (transaction.status === 'mined' && transaction.confirmations >= config.requiredConfirmations) return 'deployed'
if (transaction.status === 'mined' && transaction.confirmations < config.requiredConfirmations) return 'confirming'
if (transaction.status !== 'mined') return 'pending'
}

0 comments on commit d179e44

Please sign in to comment.