"sync"
"time"
+ "github.com/golang/groupcache/lru"
+ dbm "github.com/tendermint/tmlibs/db"
+
"github.com/bytom/blockchain/pin"
"github.com/bytom/blockchain/signers"
"github.com/bytom/blockchain/txbuilder"
"github.com/bytom/log"
"github.com/bytom/protocol"
"github.com/bytom/protocol/vm/vmutil"
- "github.com/golang/groupcache/lru"
-
- dbm "github.com/tendermint/tmlibs/db"
)
const maxAccountCache = 1000
func (m *Manager) QueryAll(ctx context.Context) (interface{}, error) {
ret := make([]interface{}, 0)
- iter := m.db.Iterator()
+ iter := m.db.IteratorPrefix([]byte("acc"))
for iter.Next() {
- key := string(iter.Key())
- if key[:3] != "acc" {
- continue
- }
ret = append(ret, string(iter.Value()))
}
"github.com/bytom/blockchain/query"
"github.com/bytom/blockchain/signers"
"github.com/bytom/crypto/sha3pool"
+ chainjson "github.com/bytom/encoding/json"
"github.com/bytom/errors"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/legacy"
-
- chainjson "github.com/bytom/encoding/json"
)
const (
)
type AccountUTXOs struct {
- OutputID []byte
- AssetID []byte
- Amount uint64
- AccountID string
- CpIndex uint64
- Program []byte
- InBlock uint64
- SourceID []byte
- SourcePos uint64
- RefData []byte
- Change bool
+ OutputID []byte
+ AssetID []byte
+ Amount uint64
+ AccountID string
+ ProgramIndex uint64
+ Program []byte
+ BlockHeight uint64
+ SourceID []byte
+ SourcePos uint64
+ RefData []byte
+ Change bool
}
var emptyJSONObject = json.RawMessage(`{}`)
var au *AccountUTXOs
for _, out := range outs {
au = &AccountUTXOs{OutputID: out.OutputID.Bytes(),
- AssetID: out.AssetId.Bytes(),
- Amount: out.Amount,
- AccountID: out.AccountID,
- CpIndex: out.keyIndex,
- Program: out.ControlProgram,
- InBlock: block.Height,
- SourceID: out.sourceID.Bytes(),
- SourcePos: out.sourcePos,
- RefData: out.refData.Bytes(),
- Change: out.change}
+ AssetID: out.AssetId.Bytes(),
+ Amount: out.Amount,
+ AccountID: out.AccountID,
+ ProgramIndex: out.keyIndex,
+ Program: out.ControlProgram,
+ BlockHeight: block.Height,
+ SourceID: out.sourceID.Bytes(),
+ SourcePos: out.sourcePos,
+ RefData: out.refData.Bytes(),
+ Change: out.change}
accountutxo, err := json.Marshal(au)
if err != nil {
"sync/atomic"
"time"
+ dbm "github.com/tendermint/tmlibs/db"
+
"github.com/bytom/blockchain/pin"
"github.com/bytom/consensus"
"github.com/bytom/errors"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/legacy"
"github.com/bytom/sync/idempotency"
-
- dbm "github.com/tendermint/tmlibs/db"
)
var (
rawRefData [32]byte
)
- iter := db.Iterator()
+ iter := db.IteratorPrefix([]byte("acu"))
for iter.Next() {
- key := string(iter.Key())
- if key[:3] != "acu" {
- continue
- }
- err := json.Unmarshal(iter.Value(), &au)
- if err != nil {
+ if err := json.Unmarshal(iter.Value(), &au); err != nil {
return nil, errors.Wrap(err)
}
if (au.AccountID == src.AccountID) &&
(bytes.Equal(au.AssetID, src.AssetID.Bytes())) &&
- (au.InBlock > height) {
+ (au.BlockHeight > height) {
copy(rawOutputID[:], au.OutputID)
copy(rawSourceID[:], au.SourceID)
ControlProgram: au.Program,
RefDataHash: bc.NewHash(rawRefData),
AccountID: src.AccountID,
- ControlProgramIndex: au.CpIndex,
+ ControlProgramIndex: au.ProgramIndex,
})
}
u.AccountID = au.AccountID
u.AssetID = bc.NewAssetID(*rawAssetID)
u.Amount = au.Amount
- u.ControlProgramIndex = au.CpIndex
+ u.ControlProgramIndex = au.ProgramIndex
u.ControlProgram = au.Program
u.SourceID = bc.NewHash(*rawSourceID)
u.SourcePos = au.SourcePos
"encoding/json"
"sync"
- "golang.org/x/crypto/sha3"
-
"github.com/golang/groupcache/lru"
"github.com/golang/groupcache/singleflight"
dbm "github.com/tendermint/tmlibs/db"
+ "golang.org/x/crypto/sha3"
"github.com/bytom/blockchain/signers"
"github.com/bytom/crypto/ed25519"
"github.com/bytom/protocol"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/vm/vmutil"
- //"github.com/bytom/log"
)
const maxAssetCache = 1000
reg.db.Set(asset_id, json.RawMessage(ass))
}
- /* asset, err = reg.insertAsset(ctx, asset, clientToken)
- if err != nil {
- return nil, errors.Wrap(err, "inserting asset")
- }
-
- err = insertAssetTags(ctx, reg.db, asset.AssetID, tags)
- if err != nil {
- return nil, errors.Wrap(err, "inserting asset tags")
- }
- */
err = reg.indexAnnotatedAsset(ctx, asset)
if err != nil {
return nil, errors.Wrap(err, "indexing annotated asset")
asset.Tags = tags
- // Perform persistent updates
- /*
- err = insertAssetTags(ctx, reg.db, asset.AssetID, asset.Tags)
- if err != nil {
- return errors.Wrap(err, "inserting asset tags")
- }
-
- err = reg.indexAnnotatedAsset(ctx, asset)
- if err != nil {
- return errors.Wrap(err, "update asset index")
- }
- */
- // Revise cache
-
reg.cacheMu.Lock()
reg.cache.Add(asset.AssetID, asset)
reg.cacheMu.Unlock()
}
untypedAsset, err := reg.aliasGroup.Do(alias, func() (interface{}, error) {
- // asset, err := assetQuery(ctx, reg.db, "assets.alias=$1", alias)
- // return asset, err
return nil, nil
})
return ret, nil
}
-// insertAsset adds the asset to the database. If the asset has a client token,
-// and there already exists an asset with that client token, insertAsset will
-// lookup and return the existing asset instead.
-/*
-func (reg *Registry) insertAsset(ctx context.Context, asset *Asset, clientToken string) (*Asset, error) {
- const q = `
- INSERT INTO assets
- (id, alias, signer_id, initial_block_hash, vm_version, issuance_program, definition, client_token)
- VALUES($1::bytea, $2, $3, $4, $5, $6, $7, $8)
- ON CONFLICT (client_token) DO NOTHING
- RETURNING sort_id
- `
- var signerID sql.NullString
- if asset.Signer != nil {
- signerID = sql.NullString{Valid: true, String: asset.Signer.ID}
- }
-
- nullToken := sql.NullString{
- String: clientToken,
- Valid: clientToken != "",
- }
-
- err := reg.db.QueryRowContext(
- ctx, q,
- asset.AssetID, asset.Alias, signerID,
- asset.InitialBlockHash, asset.VMVersion, asset.IssuanceProgram,
- asset.rawDefinition, nullToken,
- ).Scan(&asset.sortID)
-
- if pg.IsUniqueViolation(err) {
- return nil, errors.WithDetail(ErrDuplicateAlias, "an asset with the provided alias already exists")
- } else if err == sql.ErrNoRows && clientToken != "" {
- // There is already an asset with the provided client
- // token. We should return the existing asset.
- asset, err = assetByClientToken(ctx, reg.db, clientToken)
- if err != nil {
- return nil, errors.Wrap(err, "retrieving existing asset")
- }
- } else if err != nil {
- return nil, errors.Wrap(err)
- }
- return asset, nil
-}
-
-// insertAssetTags inserts a set of tags for the given assetID.
-// It must take place inside a database transaction.
-
-func insertAssetTags(ctx context.Context, db pg.DB, assetID bc.AssetID, tags map[string]interface{}) error {
- tagsParam, err := mapToNullString(tags)
- if err != nil {
- return errors.Wrap(err)
- }
-
- const q = `
- INSERT INTO asset_tags (asset_id, tags) VALUES ($1, $2)
- ON CONFLICT (asset_id) DO UPDATE SET tags = $2
- `
- _, err = db.ExecContext(ctx, q, assetID, tagsParam)
- if err != nil {
- return errors.Wrap(err)
- }
-
- return nil
-}
-
-// assetByClientToken loads an asset from the database using its client token.
-
-func assetByClientToken(ctx context.Context, db pg.DB, clientToken string) (*Asset, error) {
- return assetQuery(ctx, db, "assets.client_token=$1", clientToken)
-}
-
-func assetQuery(ctx context.Context, db pg.DB, pred string, args ...interface{}) (*Asset, error) {
- const baseQ = `
- SELECT assets.id, assets.alias, assets.vm_version, assets.issuance_program, assets.definition,
- assets.initial_block_hash, assets.sort_id,
- signers.id, COALESCE(signers.type, ''), COALESCE(signers.xpubs, '{}'),
- COALESCE(signers.quorum, 0), COALESCE(signers.key_index, 0),
- asset_tags.tags
- FROM assets
- LEFT JOIN signers ON signers.id=assets.signer_id
- LEFT JOIN asset_tags ON asset_tags.asset_id=assets.id
- WHERE %s
- LIMIT 1
- `
-
- var (
- a Asset
- alias sql.NullString
- signerID sql.NullString
- signerType string
- quorum int
- keyIndex uint64
- xpubs [][]byte
- tags []byte
- )
- err := db.QueryRowContext(ctx, fmt.Sprintf(baseQ, pred), args...).Scan(
- &a.AssetID,
- &a.Alias,
- &a.VMVersion,
- &a.IssuanceProgram,
- &a.rawDefinition,
- &a.InitialBlockHash,
- &a.sortID,
- &signerID,
- &signerType,
- (*pq.ByteaArray)(&xpubs),
- &quorum,
- &keyIndex,
- &tags,
- )
- if err == sql.ErrNoRows {
- return nil, pg.ErrUserInputNotFound
- } else if err != nil {
- return nil, err
- }
-
- if signerID.Valid {
- a.Signer, err = signers.New(signerID.String, signerType, xpubs, quorum, keyIndex)
- if err != nil {
- return nil, err
- }
- }
-
- if alias.Valid {
- a.Alias = &alias.String
- }
-
- if len(tags) > 0 {
- err := json.Unmarshal(tags, &a.Tags)
- if err != nil {
- return nil, errors.Wrap(err)
- }
- }
- if len(a.rawDefinition) > 0 {
- // ignore errors; non-JSON asset definitions can still end up
- // on the blockchain from non-Chain Core clients.
- _ = json.Unmarshal(a.rawDefinition, &a.definition)
- }
-
- return &a, nil
-
-}
-*/
// serializeAssetDef produces a canonical byte representation of an asset
// definition. Currently, this is implemented using pretty-printed JSON.
// As is the standard for Go's map[string] serialization, object keys will
prog, err := builder.Build()
return prog, 1, err
}
-
-/*
-func mapToNullString(in map[string]interface{}) (*sql.NullString, error) {
- var mapJSON []byte
- if len(in) != 0 {
- var err error
- mapJSON, err = json.Marshal(in)
- if err != nil {
- return nil, errors.Wrap(err)
- }
- }
- return &sql.NullString{String: string(mapJSON), Valid: len(mapJSON) > 0}, nil
-}
-*/
"sort"
"sync"
+ dbm "github.com/tendermint/tmlibs/db"
+
"github.com/bytom/errors"
"github.com/bytom/log"
"github.com/bytom/protocol"
"github.com/bytom/protocol/bc/legacy"
-
- dbm "github.com/tendermint/tmlibs/db"
)
const processorWorkers = 10
Name string
Height uint64
}{}
- iter := s.DB.Iterator()
+
+ iter := s.DB.IteratorPrefix([]byte("blp"))
for iter.Next() {
- key := string(iter.Key())
- if key[:3] != "blp" {
- continue
- }
+
err := json.Unmarshal(iter.Value(), &block_processor)
if err != nil {
return errors.New("failed unmarshal this block_processor.")
AccountUTXOFmt = `
{
"OutputID":"%x","AssetID":"%x","Amount":"%d",
- "AccountID":"%s","CpIndex":"%d","Program":"%x",
- "InBlock":"%d","SourceID":"%x","SourcePos":"%d",
+ "AccountID":"%s","ProgramIndex":"%d","Program":"%x",
+ "BlockHeight":"%d","SourceID":"%x","SourcePos":"%d",
"RefData":"%x","Change":"%t"
}`
)
accutoxs = []account.AccountUTXOs{}
)
- iter := bcr.pinStore.DB.Iterator()
+ iter := bcr.pinStore.DB.IteratorPrefix([]byte("acu"))
for iter.Next() {
- key := string(iter.Key())
- if key[:3] != "acu" {
- continue
- }
err := json.Unmarshal(iter.Value(), &au)
if err != nil {
restring = fmt.Sprintf(AccountUTXOFmt,
res.OutputID, res.AssetID, res.Amount,
- res.AccountID, res.CpIndex, res.Program,
- res.InBlock, res.SourceID, res.SourcePos,
+ res.AccountID, res.ProgramIndex, res.Program,
+ res.BlockHeight, res.SourceID, res.SourcePos,
res.RefData, res.Change)
response = append(response, restring)
import (
"context"
+ stdjson "encoding/json"
"fmt"
"os"
"strconv"
"time"
+ bchain "github.com/bytom/blockchain"
"github.com/bytom/blockchain/rpc"
"github.com/bytom/blockchain/txbuilder"
"github.com/bytom/crypto/ed25519/chainkd"
"github.com/bytom/encoding/json"
-
- stdjson "encoding/json"
- bchain "github.com/bytom/blockchain"
)
type accUTXOShort struct {
-hash: 93f15c9766ea826c29a91f545c42172eafd8c61e39c1d81617114ad1a9c9eaf2
-updated: 2017-05-18T06:13:24.295793122-04:00
+hash: 4f15d2d062129c7ddc5d485e2180c9fad7d56e4006e1d3ff0fb1601711ca3f6d
+updated: 2017-10-28T10:18:01.957773712+08:00
imports:
- name: github.com/btcsuite/btcd
version: 53f55a46349aa8f44b90895047e843666991cf24
subpackages:
- btcec
-- name: github.com/davecgh/go-spew
- version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9
- subpackages:
- - spew
+- name: github.com/codahale/hdrhistogram
+ version: 3a0bb77429bd3a61596f5e8a3172445844342120
- name: github.com/ebuchman/fail-test
version: 95f809107225be108efcf10a3509e4ea6ceef3c4
- name: github.com/fsnotify/fsnotify
- log/term
- name: github.com/go-logfmt/logfmt
version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5
+- name: github.com/go-playground/locales
+ version: e4cbcb5d0652150d40ad0646651076b6bd2be4f6
+ subpackages:
+ - currency
+- name: github.com/go-playground/universal-translator
+ version: 71201497bace774495daed26a3874fd339e0b538
- name: github.com/go-stack/stack
version: 7a2f19628aabfe68f0766b59e74d6315f8347d22
- name: github.com/gogo/protobuf
version: 9df9efe4c742f1a2bfdedf1c3b6902fc6e814c6b
subpackages:
- proto
+- name: github.com/golang/crypto
+ version: 2509b142fb2b797aa7587dad548f113b2c0f20ce
+ subpackages:
+ - nacl/box
+ - nacl/secretbox
+ - ripemd160
+- name: github.com/golang/groupcache
+ version: b710c8433bd175204919eb38776e944233235d03
+ subpackages:
+ - lru
+ - singleflight
+- name: github.com/golang/net
+ version: c73622c77280266305273cb545f54516ced95b93
+ subpackages:
+ - context
- name: github.com/golang/protobuf
version: fec3b39b059c0f88fa6b20f5ed012b1aa203a8b4
subpackages:
- proto
- ptypes/any
-- name: github.com/golang/groupcache
- name: github.com/golang/snappy
version: 553a641470496b2327abcac10b36396bd98e45c9
- name: github.com/gorilla/websocket
version: c42d9e0ca023e2198120196f842701bb4c55d7b9
- name: github.com/kr/logfmt
version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0
+- name: github.com/kr/secureheader
+ version: a4295c4b19606af8e3366057e129204fb8b77411
- name: github.com/magiconair/properties
version: 51463bfca2576e06c62a8504b5c0f06d61312647
- name: github.com/mitchellh/mapstructure
version: cc8532a8e9a55ea36402aa21efdf403a60d34096
+- name: github.com/pborman/uuid
+ version: e790cca94e6cc75c7064b1332e63811d4aae1a53
- name: github.com/pelletier/go-buffruneio
version: c37440a7cf42ac63b919c752ca73a85067e05992
- name: github.com/pelletier/go-toml
version: 5c26a6ff6fd178719e15decac1c8196da0d7d6d1
- name: github.com/pkg/errors
version: c605e284fe17294bda444b34710735b29d1a9d90
-- name: github.com/pmezard/go-difflib
- version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
- subpackages:
- - difflib
+- name: github.com/rjeczalik/notify
+ version: 767eb674ef14b09119b2fff3601e64558d530c47
+- name: github.com/sirupsen/logrus
+ version: 89742aefa4b206dcf400792f3bd35b542998eb3b
- name: github.com/spf13/afero
version: 9be650865eab0c12963d8753212f4f9c66cdcf12
subpackages:
version: 864d1f80b36b440bde030a5c18d8ac3aa8c2949d
subpackages:
- client
- - example/counter
- example/dummy
- - server
- types
- name: github.com/tendermint/ed25519
version: 1f52c6f8b8a5c7908aff4497c186af344b428925
subpackages:
- data
- data/base58
-- name: github.com/tendermint/merkleeyes
- version: a0e73e1ac3e18e12a007520a4ea2c9822256e307
- subpackages:
- - app
- - client
- - iavl
- - testutil
- name: github.com/tendermint/tmlibs
- version: 306795ae1d8e4f4a10dcc8bdb32a00455843c9d5
+ version: d9525c0fb671204450b160807480e1263053fb20
subpackages:
- autofile
- cli
- flowrate
- log
- merkle
- - test
-- name: github.com/codahale/hdrhistogram
-- name: github.com/golang/crypto
-- name: github.com/golang/net
-- name: github.com/golang/text
-- name: github.com/golang/tools
-- name: github.com/golang/time
-- name: github.com/kr/secureheader
-- name: github.com/pborman/uuid
-- name: github.com/rjeczalik/notify
-- name: github.com/sirupsen/logrus
+- name: golang.org/x/crypto
+ version: 84f24dfdf3c414ed893ca1b318d0045ef5a1f607
+ subpackages:
+ - curve25519
+ - nacl/box
+ - nacl/secretbox
+ - openpgp/armor
+ - openpgp/errors
+ - pbkdf2
+ - poly1305
+ - ripemd160
+ - salsa20/salsa
+ - scrypt
+ - sha3
+ - ssh/terminal
+- name: golang.org/x/net
+ version: 8663ed5da4fd087c3cfb99a996e628b72e2f0948
+ subpackages:
+ - context
+ - http2
+ - http2/hpack
+ - idna
+ - internal/timeseries
+ - lex/httplex
+ - trace
- name: golang.org/x/sys
version: e62c3de784db939836898e5c19ffd41bece347da
subpackages:
- unix
+- name: golang.org/x/text
+ version: 6353ef0f924300eea566d3438817aa4d3374817e
+ subpackages:
+ - secure/bidirule
+ - transform
+ - unicode/bidi
+ - unicode/norm
+- name: golang.org/x/time
+ version: 6dc17368e09b0e8634d71cac8168d853e869a0c7
+ subpackages:
+ - rate
- name: google.golang.org/genproto
version: bb3573be0c484136831138976d444b8754777aff
subpackages:
- status
- tap
- transport
+- name: gopkg.in/go-playground/validator.v9
+ version: 1304298bf10d085adec514b076772a79c9cadb6b
- name: gopkg.in/yaml.v2
version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b
-testImports: []
+testImports:
+- name: github.com/davecgh/go-spew
+ version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9
+ subpackages:
+ - spew
+- name: github.com/pmezard/go-difflib
+ version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
+ subpackages:
+ - difflib
+- name: github.com/tendermint/merkleeyes
+ version: 2f6e5d31e7a35045d8d0a5895cb1fec33dd4d32b
+ subpackages:
+ - app
+ - iavl
+ - testutil
subpackages:
- data
- package: github.com/tendermint/tmlibs
- version: v0.2.0
+ version: v0.4.0
subpackages:
- autofile
- cli
"sync"
"time"
+ "github.com/kr/secureheader"
+ log "github.com/sirupsen/logrus"
+ crypto "github.com/tendermint/go-crypto"
+ wire "github.com/tendermint/go-wire"
+ cmn "github.com/tendermint/tmlibs/common"
+ dbm "github.com/tendermint/tmlibs/db"
+ _ "net/http/pprof"
+
+ bc "github.com/bytom/blockchain"
"github.com/bytom/blockchain/account"
"github.com/bytom/blockchain/asset"
"github.com/bytom/blockchain/pin"
"github.com/bytom/blockchain/pseudohsm"
"github.com/bytom/blockchain/txdb"
+ cfg "github.com/bytom/config"
"github.com/bytom/consensus"
"github.com/bytom/env"
"github.com/bytom/errors"
+ bytomlog "github.com/bytom/log"
"github.com/bytom/net/http/reqid"
+ p2p "github.com/bytom/p2p"
"github.com/bytom/protocol"
"github.com/bytom/protocol/bc/legacy"
"github.com/bytom/types"
"github.com/bytom/version"
- "github.com/kr/secureheader"
-
- bc "github.com/bytom/blockchain"
- cfg "github.com/bytom/config"
- bytomlog "github.com/bytom/log"
- p2p "github.com/bytom/p2p"
- log "github.com/sirupsen/logrus"
- crypto "github.com/tendermint/go-crypto"
- wire "github.com/tendermint/go-wire"
- cmn "github.com/tendermint/tmlibs/common"
- dbm "github.com/tendermint/tmlibs/db"
- _ "net/http/pprof"
)
const (
"sync"
"time"
+ log "github.com/sirupsen/logrus"
+
"github.com/bytom/errors"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/legacy"
"github.com/bytom/protocol/state"
- log "github.com/sirupsen/logrus"
)
// maxCachedValidatedTxs is the max number of validated txs to cache.