Skip to content

Commit

Permalink
Dev (#164)
Browse files Browse the repository at this point in the history
* modify account

* modify genesis_test

* add get delegated balance

* fix test

* add opt for opSnapBalance

* add msg.assetid for solidity

* recompile VEN.sol due to solc change

* modify assetid type from address to uint256

* modify action and acccount

* modify action type

* Update test_utils.go

* fix genesis_test

* Update asset.go

* add gasAllot to receipt

* modify payload data

* fix testcase for receipt

* write right json format for receipt struct

* modify genesis account

* add log info

* fix genesis_test

* add contract log

* contract log storage

* fix jsonrpc about dpos

* add bft irreversible & ErrTooMuchRreversible

* fix genesis test

* fix extra reward bug

* modify action toname

* fix contract log store bug

* modify action

* add rpc GetAssetAmountByTime

* odify action type

* sync from dev branch

* support import/export block

* odify accountmanager process

* delete package

* add aciton value check

* syn from dev

* syn from dev

* syn from dev

* modify import block

* fix bug

* add test case

* add account ID

* add rpc getaccountbyid

* fix bug

* fixbug getbalancebytime

* add destroyasset for contract

* fixvmbug

* add value check

* actioncheck

* action test case

* fix too much rreversible & recover system

* support subaccount and subasset

* add cadidate counter

* add test

* fix bug

* fix bug

* modify subasset

* fix bug

* fix library

* modify get block detail log rpc

* modify BlockAndResult struct

* change to multi signature

delete useless log

delete useless binary file

* add transaction test

* delete unvaild file

* prevent the system account from doing evil

* detailed tx interface

* modify snapshot

* fix take over bug

* using account name with bloom

* support access all balance from asset and subAsset

* bloom encoding

* using function from common bytes

* delete useless gas params

* add account and asset level config in genesis block

* receipts seems dont contains detailedtx, using transaction index instead

* modify asset limit

* modify snapshot

* modify get balance

* add getdelegate api

* add check account is exist by id

* change name to id in contract

* add contract get all balance

* add contract get delegate

* delete redundant code

* fix bug

* add encrypt func

* fix validate cadidate bound bug

* fix account is null

* add account and asset create number

* add gas type

* fix bug

* fix bug CalcProposedIrreversible

* modify gas distribute

* fix bug

* modify snapshot flag

* fix acct nil bug

* add asset nil check

* modify account not exist

* fix vm bug

* modify account and asset name

* get all txs by account or bloom string

* change to filter func for reuse purpose

* hexutil Bytes argment

* add go vet ckeck

* fix txpool unit test fail error

* fix makefile

* refined implement (#135)

* get all txs by account or bloom string

* change to filter func for reuse purpose

* hexutil Bytes argment

* refine implement

* fix bftirreversible bug

* adjust value about dpos transaction

* add get account create time

* panic when sign is empty

* check to

* check to

* add updateAuthorThreshold

* delete useless log

* modify testcase

* modify account founder is nil

* fix genesis defined

* add asset attribute

* fix worker

* optimize signer code

* cache sender in transaction before obtaining lock

* move account mananger in validateTx

* Review (#144)

* get all txs by account or bloom string

* change to filter func for reuse purpose

* hexutil Bytes argment

* refine implement

* fix genesis

* modify config

* fix bug

* enode -> fnode

* delete DatabaseVersion

* fnode test fix

* fork controller refined

* recover SetupGenesisBlock func panic

* fixed ft cmd config priority level

* blockchain check state

* query bad blocks

* modify blockchain event

* only relative logs are returned. required by wallet

* bad block return filled block structure

* append fix

* merge

* merge

* remove local wallet

* add command p2p name and id flags

* modify internal log

* add cryptocalc func

* redo fmt

* test getaccounttime

* remove types/action.go println

* modify genesis internal log

* Bug contract (#152)

* fix bug

* Txpool config (#153)

* add txpool config check

* add makefile tmp_release

* add crypto byte gas consume

* fix asset contract (#157)

* enc len calc error

* fix asset contract (#158)

* modify instruction action toAccount

* fix gas cost

* rename internalTx and lower sections of rpc results (#163)

* get all txs by account or bloom string

* change to filter func for reuse purpose

* hexutil Bytes argment

* refine implement

* enode -> fnode

* lower first character

* rename internalTx-> DetailAction InternalLog -> InternalAction
  • Loading branch information
erickyan86 authored Apr 23, 2019
1 parent 53fb990 commit b4bb3a9
Show file tree
Hide file tree
Showing 201 changed files with 10,298 additions and 8,410 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# git config --global core.excludesfile ~/.gitignore_global
build/bin
build/_workspace
build/test_sdk

*.bak

Expand Down
26 changes: 16 additions & 10 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Copyright 2018 The Fractal Team Authors
# This file is part of the fractal project.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Make sure to check the documentation at http://goreleaser.com
builds:
- binary: ft
Expand All @@ -10,15 +25,6 @@ builds:
goarch:
- amd64
- 386
- binary: ftkey
main: ./cmd/ftkey
goos:
- windows
- darwin
- linux
goarch:
- amd64
- 386
- binary: ftfinder
main: ./cmd/ftfinder
goos:
Expand Down
28 changes: 16 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SHELL:=/bin/bash
REPO := $(shell pwd)
GOFILES_NOVENDOR := $(shell go list -f "{{.Dir}}" ./...)
PACKAGES_NOVENDOR := $(shell go list ./...)
PACKAGES_NOVENDOR := $(shell go list ./... | grep -v test)
WORK_SPACE := ${REPO}/build/_workspace
FT_DIR :=${WORK_SPACE}/src/github.com/fractalplatform
TEMP_GOPATH := $(GOPATH)
Expand Down Expand Up @@ -50,6 +50,13 @@ fmt:
@echo "Correcting any formatting style corrections."
@gofmt -l -w ${GOFILES_NOVENDOR}

# vet runs extended compilation checks to find recommendations for
# suspicious code constructs.
.PHONY: vet
vet:
@echo "Running go vet."
@go vet ${PACKAGES_NOVENDOR}

### Building project

# Output commit_hash but only if we have the git repo (e.g. not in docker build
Expand All @@ -64,19 +71,14 @@ build_workspace:

# build all targets
.PHONY: all
all:check build_workspace build_ft build_ftkey build_ftfinder
all:check build_workspace build_ft build_ftfinder

# build ft
.PHONY: build_ft
build_ft: commit_hash check build_workspace
@echo "Building ft."
$(call build,ft)

# build ftkey
.PHONY: build_ftkey
build_ftkey: commit_hash check build_workspace
@echo "Building ftkey."
$(call build,ftkey)

# build ftfinder
.PHONY: build_ftfinder
Expand All @@ -87,7 +89,7 @@ build_ftfinder: commit_hash check build_workspace
### Test

.PHONY: test
test: build_workspace
test: all
@cd ${FT_DIR}/fractal && scripts/test.sh

.PHONY: test_win
Expand Down Expand Up @@ -121,13 +123,15 @@ docs: CHANGELOG NOTES

# Tag the current HEAD commit with the current release defined in
.PHONY: tag_release
tag_release: test check docs all
tag_release: test check docs
@scripts/tag_release.sh

.PHONY: release
release: test check docs all
release: test check docs
@scripts/is_checkout_dirty.sh || (echo "checkout is dirty so not releasing!" && exit 1)
@export GOPATH=${TEMP_GOPATH} && scripts/release.sh



.PHONY: tmp_release
tmp_release: test check
@echo "Building and releasing"
@export GOPATH=${TEMP_GOPATH} && goreleaser --snapshot --rm-dist
161 changes: 132 additions & 29 deletions accountmanager/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package accountmanager

import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/log"
"github.com/fractalplatform/fractal/asset"
"github.com/fractalplatform/fractal/common"
"github.com/fractalplatform/fractal/crypto"
Expand All @@ -30,6 +32,17 @@ type AssetBalance struct {
Balance *big.Int `json:"balance"`
}

type recoverActionResult struct {
acctAuthors map[common.Name]*accountAuthor
}

type accountAuthor struct {
threshold uint64
updateAuthorThreshold uint64
version uint64
indexWeight map[uint64]uint64
}

func newAssetBalance(assetID uint64, amount *big.Int) *AssetBalance {
ab := AssetBalance{
AssetID: assetID,
Expand All @@ -41,16 +54,22 @@ func newAssetBalance(assetID uint64, amount *big.Int) *AssetBalance {
//Account account object
type Account struct {
//LastTime *big.Int
AcctName common.Name `json:"accountName"`
Founder common.Name `json:"founder"`
ChargeRatio uint64 `json:"chargeRatio"`
Nonce uint64 `json:"nonce"`
PublicKey common.PubKey `json:"publicKey"`
Code []byte `json:"code"`
CodeHash common.Hash `json:"codeHash"`
CodeSize uint64 `json:"codeSize"`
AcctName common.Name `json:"accountName"`
Founder common.Name `json:"founder"`
AccountID uint64 `json:"accountID"`
Number uint64 `json:"number"`
ChargeRatio uint64 `json:"chargeRatio"`
Nonce uint64 `json:"nonce"`
Code []byte `json:"code"`
CodeHash common.Hash `json:"codeHash"`
CodeSize uint64 `json:"codeSize"`
Threshold uint64 `json:"threshold"`
UpdateAuthorThreshold uint64 `json:"updateAuthorThreshold"`
AuthorVersion uint64 `json:"authorVersion"`
//sort by asset id asc
Balances []*AssetBalance `json:"balances"`
//realated account, pubkey and address
Authors []*common.Author `json:"authors"`
//code Suicide
Suicide bool `json:"suicide"`
//account destroy
Expand All @@ -59,25 +78,40 @@ type Account struct {

// NewAccount create a new account object.
func NewAccount(accountName common.Name, founderName common.Name, pubkey common.PubKey) (*Account, error) {
if !common.IsValidName(accountName.String()) {
if !common.IsValidAccountName(accountName.String()) {
return nil, ErrAccountNameInvalid
}

auth := common.NewAuthor(pubkey, 1)
acctObject := Account{
AcctName: accountName,
Founder: founderName,
ChargeRatio: 0,
PublicKey: pubkey,
Nonce: 0,
Balances: make([]*AssetBalance, 0),
Code: make([]byte, 0),
CodeHash: crypto.Keccak256Hash(nil),
Suicide: false,
Destroy: false,
AcctName: accountName,
Founder: founderName,
AccountID: 0,
Number: 0,
ChargeRatio: 0,
Nonce: 0,
Balances: make([]*AssetBalance, 0),
Code: make([]byte, 0),
CodeHash: crypto.Keccak256Hash(nil),
Threshold: 1,
UpdateAuthorThreshold: 1,
AuthorVersion: 1,
Authors: []*common.Author{auth},
Suicide: false,
Destroy: false,
}
return &acctObject, nil
}

//HaveCode check account have code
func (a *Account) HaveCode() bool {
if a.GetCodeSize() == 0 {
return false
}
return true
}

// IsEmpty check account empty
func (a *Account) IsEmpty() bool {
if a.GetCodeSize() == 0 && len(a.Balances) == 0 && a.Nonce == 0 {
return true
Expand All @@ -90,18 +124,42 @@ func (a *Account) GetName() common.Name {
return a.AcctName
}

//GetFounder return account object founder
func (a *Account) GetFounder() common.Name {
return a.Founder
}

//SetFounder set account object founder
func (a *Account) SetFounder(f common.Name) {
a.Founder = f
}

//GetAccountID return account object id
func (a *Account) GetAccountID() uint64 {
return a.AccountID
}

//SetAccountID set account object id
func (a *Account) SetAccountID(id uint64) {
a.AccountID = id
}

//GetAccountNumber return account object number
func (a *Account) GetAccountNumber() uint64 {
return a.Number
}

//SetAccountNumber set account object number
func (a *Account) SetAccountNumber(number uint64) {
a.Number = number
}

//GetChargeRatio return account charge ratio
func (a *Account) GetChargeRatio() uint64 {
return a.ChargeRatio
}

//SetChargeRatio set account object charge ratio
func (a *Account) SetChargeRatio(ra uint64) {
a.ChargeRatio = ra
}
Expand All @@ -116,14 +174,12 @@ func (a *Account) SetNonce(nonce uint64) {
a.Nonce = nonce
}

//GetPubKey get bugkey
func (a *Account) GetPubKey() common.PubKey {
return a.PublicKey
func (a *Account) GetAuthorVersion() uint64 {
return a.AuthorVersion
}

//SetPubKey set pub key
func (a *Account) SetPubKey(pubkey common.PubKey) {
a.PublicKey.SetBytes(pubkey.Bytes())
func (a *Account) SetAuthorVersion() {
a.AuthorVersion++
}

//GetCode get code
Expand All @@ -150,6 +206,52 @@ func (a *Account) SetCode(code []byte) error {
return nil
}

func (a *Account) GetThreshold() uint64 {
return a.Threshold
}

func (a *Account) SetThreshold(t uint64) {
a.Threshold = t
}

func (a *Account) SetUpdateAuthorThreshold(t uint64) {
a.UpdateAuthorThreshold = t
}

func (a *Account) GetUpdateAuthorThreshold() uint64 {
return a.UpdateAuthorThreshold
}

func (a *Account) AddAuthor(author *common.Author) error {
for _, auth := range a.Authors {
if author.Owner.String() == auth.Owner.String() {
return fmt.Errorf("%s already exist", auth.Owner.String())
}
}
a.Authors = append(a.Authors, author)
return nil
}

func (a *Account) UpdateAuthor(author *common.Author) error {
for _, auth := range a.Authors {
if author.Owner.String() == auth.Owner.String() {
auth.Weight = author.Weight
break
}
}
return nil
}

func (a *Account) DeleteAuthor(author *common.Author) error {
for i, auth := range a.Authors {
if author.Owner.String() == auth.Owner.String() {
a.Authors = append(a.Authors[:i], a.Authors[i+1:]...)
break
}
}
return nil
}

// GetCodeHash get code hash
func (a *Account) GetCodeHash() (common.Hash, error) {
if len(a.CodeHash) == 0 {
Expand All @@ -166,6 +268,7 @@ func (a *Account) GetBalanceByID(assetID uint64) (*big.Int, error) {
if p, find := a.binarySearch(assetID); find == true {
return a.Balances[p].Balance, nil
}
log.Debug("get balance by ID", "err", ErrAccountAssetNotExist, "account", a.AcctName, "asset", assetID)
return big.NewInt(0), ErrAccountAssetNotExist
}

Expand Down Expand Up @@ -310,13 +413,13 @@ func (a *Account) SetSuicide() {
a.Suicide = true
}

//IsDestoryed is destoryed
func (a *Account) IsDestoryed() bool {
//IsDestroyed is destroyed
func (a *Account) IsDestroyed() bool {
return a.Destroy
}

//SetDestory set destory
func (a *Account) SetDestory() {
//SetDestroy set destroy
func (a *Account) SetDestroy() {
//just make a sign now
a.Destroy = true
}
Loading

0 comments on commit b4bb3a9

Please sign in to comment.