Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/neuron-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"last 2 chrome versions"
],
"dependencies": {
"@nervosnetwork/ckb-sdk-core": "0.18.0",
"@nervosnetwork/ckb-sdk-core": "0.19.0",
"@uifabric/experiments": "7.10.0",
"@uifabric/styling": "7.4.0",
"canvg": "2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
]
},
"dependencies": {
"@nervosnetwork/ckb-sdk-core": "0.18.0",
"@nervosnetwork/ckb-sdk-utils": "0.18.0",
"@nervosnetwork/ckb-sdk-core": "0.19.0",
"@nervosnetwork/ckb-sdk-utils": "0.19.0",
"bn.js": "4.11.8",
"chalk": "2.4.2",
"electron-log": "3.0.7",
Expand All @@ -51,7 +51,7 @@
"uuid": "3.3.2"
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.18.0",
"@nervosnetwork/ckb-types": "0.19.0",
"@types/electron-devtools-installer": "2.2.0",
"@types/elliptic": "6.4.8",
"@types/sqlite3": "3.1.5",
Expand Down
11 changes: 2 additions & 9 deletions packages/neuron-wallet/src/database/chain/entities/input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, BaseEntity, Column, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
import { OutPoint, Input as InputInterface, CellOutPoint } from 'types/cell-types'
import { OutPoint, Input as InputInterface } from 'types/cell-types'
import Transaction from './transaction'

/* eslint @typescript-eslint/no-unused-vars: "warn" */
Expand Down Expand Up @@ -42,7 +42,7 @@ export default class Input extends BaseEntity {
})
capacity: string | null = null

public cellOutPoint(): CellOutPoint | null {
public previousOutput(): OutPoint | null {
if (!this.outPointTxHash || !this.outPointIndex) {
return null
}
Expand All @@ -52,13 +52,6 @@ export default class Input extends BaseEntity {
}
}

public previousOutput(): OutPoint {
return {
blockHash: null,
cell: this.cellOutPoint(),
}
}

public toInterface(): InputInterface {
return {
previousOutput: this.previousOutput(),
Expand Down
11 changes: 2 additions & 9 deletions packages/neuron-wallet/src/database/chain/entities/output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, BaseEntity, Column, PrimaryColumn, ManyToOne } from 'typeorm'
import { Script, OutPoint, Cell, CellOutPoint } from 'types/cell-types'
import { Script, OutPoint, Cell } from 'types/cell-types'
import TransactionEntity from './transaction'

/* eslint @typescript-eslint/no-unused-vars: "warn" */
Expand Down Expand Up @@ -35,20 +35,13 @@ export default class Output extends BaseEntity {
})
status!: string

public cellOutPoint(): CellOutPoint {
public outPoint(): OutPoint {
return {
txHash: this.outPointTxHash,
index: this.outPointIndex,
}
}

public outPoint(): OutPoint {
return {
blockHash: null,
cell: this.cellOutPoint(),
}
}

@ManyToOne(_type => TransactionEntity, transaction => transaction.outputs, { onDelete: 'CASCADE' })
transaction!: TransactionEntity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
AfterRemove,
} from 'typeorm'
import { remote } from 'electron'
import { Witness, OutPoint, Transaction as TransactionInterface, TransactionStatus } from 'types/cell-types'
import { Witness, Transaction as TransactionInterface, TransactionStatus, CellDep } from 'types/cell-types'
import TxDbChangedSubject from 'models/subjects/tx-db-changed-subject'
import InputEntity from './input'
import OutputEntity from './output'
Expand All @@ -37,7 +37,12 @@ export default class Transaction extends BaseEntity {
@Column({
type: 'simple-json',
})
deps!: OutPoint[]
cellDeps: CellDep[] = []

@Column({
type: 'simple-json',
})
headerDeps: string[] = []

@Column({
type: 'simple-json',
Expand Down Expand Up @@ -101,7 +106,8 @@ export default class Transaction extends BaseEntity {
return {
hash: this.hash,
version: this.version,
deps: this.deps,
cellDeps: this.cellDeps,
headerDeps: this.headerDeps,
inputs,
outputs,
timestamp: this.timestamp,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class InitMigration1561695143591 implements MigrationInterface {
export class InitMigration1566959757554 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`CREATE TABLE "output" ("outPointTxHash" varchar NOT NULL, "outPointIndex" varchar NOT NULL, "capacity" varchar NOT NULL, "lock" text NOT NULL, "lockHash" varchar NOT NULL, "status" varchar NOT NULL, "transactionHash" varchar, PRIMARY KEY ("outPointTxHash", "outPointIndex"))`);
await queryRunner.query(`CREATE TABLE "transaction" ("hash" varchar PRIMARY KEY NOT NULL, "version" varchar NOT NULL, "deps" text NOT NULL, "witnesses" text NOT NULL, "timestamp" varchar, "blockNumber" varchar, "blockHash" varchar, "description" varchar, "createdAt" varchar NOT NULL, "updatedAt" varchar NOT NULL)`);
await queryRunner.query(`CREATE TABLE "transaction" ("hash" varchar PRIMARY KEY NOT NULL, "version" varchar NOT NULL, "cellDeps" text NOT NULL, "headerDeps" text NOT NULL, "witnesses" text NOT NULL, "timestamp" varchar, "blockNumber" varchar, "blockHash" varchar, "description" varchar, "status" varchar NOT NULL, "createdAt" varchar NOT NULL, "updatedAt" varchar NOT NULL, "confirmed" boolean NOT NULL)`);
await queryRunner.query(`CREATE TABLE "input" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "outPointTxHash" varchar, "outPointIndex" varchar, "since" varchar NOT NULL, "lockHash" varchar, "capacity" varchar, "transactionHash" varchar)`);
await queryRunner.query(`CREATE TABLE "sync_info" ("name" varchar PRIMARY KEY NOT NULL, "value" varchar NOT NULL)`);
await queryRunner.query(`CREATE TABLE "temporary_output" ("outPointTxHash" varchar NOT NULL, "outPointIndex" varchar NOT NULL, "capacity" varchar NOT NULL, "lock" text NOT NULL, "lockHash" varchar NOT NULL, "status" varchar NOT NULL, "transactionHash" varchar, CONSTRAINT "FK_29236a0eb11fac458990882f985" FOREIGN KEY ("transactionHash") REFERENCES "transaction" ("hash") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("outPointTxHash", "outPointIndex"))`);
Expand Down
7 changes: 2 additions & 5 deletions packages/neuron-wallet/src/database/chain/ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import Transaction from './entities/transaction'
import Input from './entities/input'
import Output from './entities/output'
import SyncInfo from './entities/sync-info'

import { InitMigration1561695143591 } from './migrations/1561695143591-InitMigration'
import { AddStatusToTx1562038960990 } from './migrations/1562038960990-AddStatusToTx'
import { AddConfirmed1565693320664 } from './migrations/1565693320664-AddConfirmed'
import { InitMigration1566959757554 } from './migrations/1566959757554-InitMigration'

export const CONNECTION_NOT_FOUND_NAME = 'ConnectionNotFoundError'

Expand All @@ -32,7 +29,7 @@ const connectOptions = async (genesisBlockHash: string): Promise<SqliteConnectio
type: 'sqlite',
database: dbPath(genesisBlockHash),
entities: [Transaction, Input, Output, SyncInfo],
migrations: [InitMigration1561695143591, AddStatusToTx1562038960990, AddConfirmed1565693320664],
migrations: [InitMigration1566959757554],
logging,
}
}
Expand Down
56 changes: 23 additions & 33 deletions packages/neuron-wallet/src/models/lock-utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import NodeService from 'services/node'
import { OutPoint, Script, ScriptHashType } from 'types/cell-types'
import env from 'env'
import { SystemScriptSubject } from './subjects/system-script'
import ConvertTo from 'types/convert-to'
import { SystemScriptSubject } from 'models/subjects/system-script'

const { core } = NodeService.getInstance()

export interface SystemScript {
codeHash: string
outPoint: OutPoint
hashType: ScriptHashType
}

const subscribed = (target: any, propertyName: string) => {
Expand All @@ -30,34 +32,27 @@ export default class LockUtils {
return this.systemScriptInfo
}

const systemCell = await core.loadSystemCell()
const systemCell = await core.loadSecp256k1Dep()
let { codeHash } = systemCell
const { outPoint } = systemCell
let { blockHash } = outPoint
let { txHash } = outPoint.cell
const { index } = outPoint.cell
const { outPoint, hashType } = systemCell
let { txHash } = outPoint
const { index } = outPoint

if (!codeHash.startsWith('0x')) {
codeHash = `0x${codeHash}`
}

if (!blockHash.startsWith('0x')) {
blockHash = `0x${blockHash}`
}

if (!txHash.startsWith('0x')) {
txHash = `0x${txHash}`
}

const systemScriptInfo = {
codeHash,
outPoint: {
blockHash,
cell: {
txHash,
index,
},
txHash,
index,
},
hashType: hashType as ScriptHashType,
}

this.systemScriptInfo = systemScriptInfo
Expand All @@ -70,26 +65,21 @@ export default class LockUtils {
SystemScriptSubject.next({ codeHash: info.codeHash })
}

// use SDK lockScriptToHash
static lockScriptToHash = (lock: Script) => {
const codeHash: string = lock!.codeHash!
const args: string[] = lock.args!
const { hashType } = lock
// TODO: should support ScriptHashType.Type in the future
const lockHash: string = core.utils.lockScriptToHash({
codeHash,
args,
hashType,
})

if (lockHash.startsWith('0x')) {
return lockHash
static computeScriptHash = async (script: Script): Promise<string> => {
const ckbScript: CKBComponents.Script = ConvertTo.toSdkScript(script)
const hash: string = await (core.rpc as any).computeScriptHash(ckbScript)
if (!hash.startsWith('0x')) {
return `0x${hash}`
}
return hash
}

return `0x${lockHash}`
// use SDK lockScriptToHash
static lockScriptToHash = async (lock: Script) => {
return LockUtils.computeScriptHash(lock)
}

static async addressToLockScript(address: string, hashType: ScriptHashType = ScriptHashType.Data): Promise<Script> {
static async addressToLockScript(address: string, hashType: ScriptHashType = ScriptHashType.Type): Promise<Script> {
const systemScript = await this.systemScript()

const lock: Script = {
Expand All @@ -100,15 +90,15 @@ export default class LockUtils {
return lock
}

static async addressToLockHash(address: string, hashType: ScriptHashType = ScriptHashType.Data): Promise<string> {
static async addressToLockHash(address: string, hashType: ScriptHashType = ScriptHashType.Type): Promise<string> {
const lock: Script = await this.addressToLockScript(address, hashType)
const lockHash: string = await this.lockScriptToHash(lock)

return lockHash
}

static async addressToAllLockHashes(address: string): Promise<string[]> {
const dataLockHash = await LockUtils.addressToLockHash(address, ScriptHashType.Data)
const dataLockHash = await LockUtils.addressToLockHash(address)
return [dataLockHash]
}

Expand Down
5 changes: 2 additions & 3 deletions packages/neuron-wallet/src/services/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ export default class CellsService {
}

private static getLiveCellEntity = async (outPoint: OutPoint): Promise<OutputEntity | undefined> => {
const cell = outPoint.cell!
const cellEntity: OutputEntity | undefined = await getConnection()
.getRepository(OutputEntity)
.findOne({
outPointTxHash: cell.txHash,
outPointIndex: cell.index,
outPointTxHash: outPoint.txHash,
outPointIndex: outPoint.index,
status: 'live',
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ export default class CheckOutput {

constructor(output: Cell) {
this.output = output
this.calcLockHash()
// this.calcLockHash()
}

public calcLockHash = (): Cell => {
public calcLockHash = async (): Promise<Cell> => {
if (this.output.lockHash) {
return this.output
}

this.output.lockHash = LockUtils.lockScriptToHash(this.output.lock)
this.output.lockHash = await LockUtils.lockScriptToHash(this.output.lock)
return this.output
}

public checkLockHash = (lockHashList: string[]): boolean | undefined => {
public checkLockHash = async (lockHashList: string[]): Promise<boolean | undefined> => {
await this.calcLockHash()
return lockHashList.includes(this.output.lockHash!)
}
}
Loading