Skip to content

Commit

Permalink
In address router, add to pendings
Browse files Browse the repository at this point in the history
  • Loading branch information
Joowon Yun committed Jun 11, 2019
1 parent a89a1fe commit b00865c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
23 changes: 11 additions & 12 deletions data/clientDist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/clientDist/bundle.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions data/clientDist/styles.css

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

6 changes: 5 additions & 1 deletion src/api/dto/addressDTO.ts
@@ -1,20 +1,24 @@
import { hycontoString } from "@glosfer/hyconjs-util"
import { Account } from "../../consensus/database/account"
import { TxDTO } from "./txDTO"
export class AddressDTO {
public static addressToDTO(address: string, account: Account) {
public static addressToDTO(address: string, account: Account, txdtos?: TxDTO[]) {
const addressDTO = new AddressDTO()
addressDTO.address = address
if (account !== undefined) {
addressDTO.balance = hycontoString(account.balance)
addressDTO.nonce = account.nonce
}
if (txdtos !== undefined) { addressDTO.pendings = txdtos }
return addressDTO
}

public address: string
public balance: string
public nonce: number

public pendings?: TxDTO[]

constructor() {
this.balance = "0"
this.nonce = 0
Expand Down
16 changes: 13 additions & 3 deletions src/api/model/addressModel.ts
@@ -1,22 +1,32 @@
import { getLogger } from "log4js"
import { Address } from "../../common/address"
import { TxPool } from "../../common/txPool"
import { Consensus } from "../../consensus/consensus"
import { Account } from "../../consensus/database/account"
import { AddressDTO } from "../dto/addressDTO"
import { TxDTO } from "../dto/txDTO"
import { RESPONSE_CODE, Responser } from "../router/responser"
const logger = getLogger("AddressModel")

export class AddressModel {
private consensus: Consensus
constructor(consensus: Consensus) {
private txPool: TxPool
constructor(consensus: Consensus, txPool: TxPool) {
this.consensus = consensus
this.txPool = txPool
}

public async getAddress(targetAddress: string) {
try {
if (targetAddress === undefined) { return Responser.missingParameter() }
const account: Account = await this.consensus.getAccount(new Address(targetAddress))
return AddressDTO.addressToDTO(targetAddress, account)
const address: Address = new Address(targetAddress)
const account: Account = await this.consensus.getAccount(address)
const { pendings, pendingAmount } = this.txPool.getAllPendingAddress(address)
const txdtos: TxDTO[] = []
for (const stx of pendings) {
txdtos.push(TxDTO.txToDTO(stx))
}
return AddressDTO.addressToDTO(targetAddress, account, txdtos)
} catch (e) {
logger.warn(`Failed to getAddress : ${e} / stack : ${e.stack}`)
return Responser.makeJsonError(RESPONSE_CODE.BAD_REQUEST, e.toString())
Expand Down
4 changes: 2 additions & 2 deletions src/api/server.tsx
Expand Up @@ -2,7 +2,7 @@ import * as bodyParser from "body-parser"
import * as timeout from "connect-timeout"
import * as express from "express"
import { getLogger } from "log4js"
import opn = require("opn")
const opn = require("opn")
import { matchRoutes } from "react-router-config"
import { userOptions } from "../main"
import { RestManager } from "../rest/restManager"
Expand Down Expand Up @@ -172,7 +172,7 @@ export class HttpServer {
this.blockModel = new BlockModel(this.hyconServer.consensus)
this.transactionModel = new TransactionModel(this.hyconServer.consensus, this.hyconServer)
this.walletModel = new WalletModel(this.hyconServer.consensus)
this.addressModel = new AddressModel(this.hyconServer.consensus)
this.addressModel = new AddressModel(this.hyconServer.consensus, this.hyconServer.txQueue)
this.networkModel = new NetworkModel(this.hyconServer.consensus, this.hyconServer.network.getPeerDatabase())
}
}
2 changes: 1 addition & 1 deletion test/database.spec.ts
@@ -1,5 +1,5 @@
import { randomBytes } from "crypto"
import { NotFoundError } from "level-errors"
const NotFoundError = require("level-errors")
import * as levelup from "levelup"
import Long = require("long")
import { AnyBlock, Block } from "../src/common/block"
Expand Down

0 comments on commit b00865c

Please sign in to comment.