Skip to content

Commit

Permalink
add snapshot interface
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekCat99 authored and elvis88 committed Feb 20, 2019
1 parent 36bc33c commit 5d1095c
Show file tree
Hide file tree
Showing 81 changed files with 8,108 additions and 688 deletions.
29 changes: 25 additions & 4 deletions accountmanager/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/fractalplatform/fractal/crypto"
)



// AssetBalance asset and balance struct
type AssetBalance struct {
AssetID uint64
Expand All @@ -40,7 +42,10 @@ func newAssetBalance(assetID uint64, amount *big.Int) *AssetBalance {

//Account account object
type Account struct {
//LastTime *big.Int
AcctName common.Name
Founder common.Name
ChargeRatio uint64
Nonce uint64
PublicKey common.PubKey
Code []byte
Expand All @@ -55,14 +60,15 @@ type Account struct {
}

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

acctObject := Account{
AcctName: accountName,
Founder: founderName,
ChargeRatio: 0,
PublicKey: pubkey,
Nonce: 0,
Balances: make([]*AssetBalance, 0),
Expand All @@ -86,6 +92,22 @@ func (a *Account) GetName() common.Name {
return a.AcctName
}

func (a *Account) GetFounder() common.Name {
return a.Founder
}

func (a *Account) SetFounder(f common.Name) {
a.Founder = f
}

func (a *Account) GetChargeRatio() uint64 {
return a.ChargeRatio
}

func (a *Account) SetChargeRatio(ra uint64) {
a.ChargeRatio = ra
}

// GetNonce get nonce
func (a *Account) GetNonce() uint64 {
return a.Nonce
Expand Down Expand Up @@ -187,9 +209,8 @@ func (a *Account) binarySearch(assetID uint64) (int64, bool) {
return high, false
}

//AddNewAssetByAssetID add a new asset to balance list and set the value to zero
//AddNewAssetByAssetID add a new asset to balance list
func (a *Account) AddNewAssetByAssetID(assetID uint64, amount *big.Int) {
//TODO dest account can recv asset
p, find := a.binarySearch(assetID)
if find {
a.Balances[p].Balance = amount
Expand Down
3 changes: 2 additions & 1 deletion accountmanager/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Test_newAssetBalance(t *testing.T) {
func TestNewAccount(t *testing.T) {
type args struct {
accountName common.Name
founderName common.Name
pubkey common.PubKey
}
tests := []struct {
Expand All @@ -57,7 +58,7 @@ func TestNewAccount(t *testing.T) {
// TODO: Add test cases.
}
for _, tt := range tests {
got, err := NewAccount(tt.args.accountName, tt.args.pubkey)
got, err := NewAccount(tt.args.accountName,tt.args.founderName, tt.args.pubkey)
if (err != nil) != tt.wantErr {
t.Errorf("%q. NewAccount() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue
Expand Down

0 comments on commit 5d1095c

Please sign in to comment.