OSDN Git Service

remove useless signer create arguments (#293)
author李永峰 <wliyongfeng@gmail.com>
Tue, 16 Jan 2018 10:41:26 +0000 (18:41 +0800)
committerPaladz <yzhu101@uottawa.ca>
Tue, 16 Jan 2018 10:41:26 +0000 (18:41 +0800)
blockchain/account/accounts.go
blockchain/account/accounts_test.go
blockchain/account/receivers_test.go
blockchain/accounts.go
blockchain/asset/asset.go
blockchain/asset/asset_test.go
blockchain/assets.go
blockchain/hsm_test.go
blockchain/signers/signers.go
blockchain/wallet/wallet.go
test/integration/standard_transaction_test.go

index 23789a0..02175ff 100755 (executable)
@@ -117,12 +117,12 @@ type Account struct {
 }
 
 // Create creates a new Account.
-func (m *Manager) Create(ctx context.Context, xpubs []chainkd.XPub, quorum int, alias string, tags map[string]interface{}, accessToken string) (*Account, error) {
+func (m *Manager) Create(xpubs []chainkd.XPub, quorum int, alias string, tags map[string]interface{}) (*Account, error) {
        if existed := m.db.Get(aliasKey(alias)); existed != nil {
                return nil, ErrDuplicateAlias
        }
 
-       id, signer, err := signers.Create(ctx, m.db, "account", xpubs, quorum, accessToken)
+       id, signer, err := signers.Create("account", xpubs, quorum)
        if err != nil {
                return nil, errors.Wrap(err)
        }
index d98fbc0..9df990c 100644 (file)
@@ -20,7 +20,7 @@ func TestCreateAccount(t *testing.T) {
        m := mockAccountManager(t)
        ctx := context.Background()
 
-       account, err := m.Create(ctx, []chainkd.XPub{testutil.TestXPub}, 1, "test-alias", nil, "")
+       account, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias", nil)
        if err != nil {
                testutil.FatalErr(t, err)
        }
@@ -39,7 +39,7 @@ func TestCreateAccountReusedAlias(t *testing.T) {
        ctx := context.Background()
        m.createTestAccount(ctx, t, "test-alias", nil)
 
-       _, err := m.Create(ctx, []chainkd.XPub{testutil.TestXPub}, 1, "test-alias", nil, "")
+       _, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias", nil)
        if errors.Root(err) != ErrDuplicateAlias {
                t.Errorf("expected %s when reusing an alias, got %v", ErrDuplicateAlias, err)
        }
@@ -96,7 +96,7 @@ func mockAccountManager(t *testing.T) *Manager {
 }
 
 func (m *Manager) createTestAccount(ctx context.Context, t testing.TB, alias string, tags map[string]interface{}) *Account {
-       account, err := m.Create(ctx, []chainkd.XPub{testutil.TestXPub}, 1, alias, tags, "")
+       account, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, alias, tags)
        if err != nil {
                testutil.FatalErr(t, err)
        }
index 3e4549e..585c52d 100644 (file)
@@ -12,7 +12,7 @@ func TestCreateReceiver(t *testing.T) {
        m := mockAccountManager(t)
        ctx := context.Background()
 
-       account, err := m.Create(ctx, []chainkd.XPub{testutil.TestXPub}, 1, "test-alias", nil, "")
+       account, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias", nil)
        if err != nil {
                testutil.FatalErr(t, err)
        }
@@ -32,7 +32,7 @@ func TestCreateAddressReceiver(t *testing.T) {
        m := mockAccountManager(t)
        ctx := context.Background()
 
-       account, err := m.Create(ctx, []chainkd.XPub{testutil.TestXPub}, 1, "test-alias", nil, "")
+       account, err := m.Create([]chainkd.XPub{testutil.TestXPub}, 1, "test-alias", nil)
        if err != nil {
                testutil.FatalErr(t, err)
        }
index 11b125f..54dc3ed 100644 (file)
@@ -15,26 +15,20 @@ func (bcr *BlockchainReactor) createAccount(ctx context.Context, ins struct {
        Quorum    int                    `json:"quorum"`
        Alias     string                 `json:"alias"`
        Tags      map[string]interface{} `json:"tags"`
-
-       // ClientToken is the application's unique token for the account. Every account
-       // should have a unique client token. The client token is used to ensure
-       // idempotency of create account requests. Duplicate create account requests
-       // with the same client_token will only create one account.
-       AccessToken string `json:"access_token"`
 }) Response {
-       acc, err := bcr.accounts.Create(nil, ins.RootXPubs, ins.Quorum, ins.Alias, ins.Tags, ins.AccessToken)
+       acc, err := bcr.accounts.Create(ins.RootXPubs, ins.Quorum, ins.Alias, ins.Tags)
        if err != nil {
-               return resWrapper(nil, err)
+               return NewErrorResponse(err)
        }
 
        annotatedAccount, err := account.Annotated(acc)
        if err != nil {
-               return resWrapper(nil, err)
+               return NewErrorResponse(err)
        }
 
        log.WithField("account ID", annotatedAccount.ID).Info("Created account")
 
-       return resWrapper(annotatedAccount)
+       return NewSuccessResponse(annotatedAccount)
 }
 
 // POST /update-account-tags
index c7c42ca..acc96f3 100755 (executable)
@@ -91,7 +91,7 @@ func (asset *Asset) RawDefinition() []byte {
 }
 
 // Define defines a new Asset.
-func (reg *Registry) Define(ctx context.Context, xpubs []chainkd.XPub, quorum int, definition map[string]interface{}, alias string, tags map[string]interface{}, clientToken string) (*Asset, error) {
+func (reg *Registry) Define(xpubs []chainkd.XPub, quorum int, definition map[string]interface{}, alias string, tags map[string]interface{}) (*Asset, error) {
        if alias == "btm" {
                return nil, ErrInternalAsset
        }
@@ -100,7 +100,7 @@ func (reg *Registry) Define(ctx context.Context, xpubs []chainkd.XPub, quorum in
                return nil, ErrDuplicateAlias
        }
 
-       _, assetSigner, err := signers.Create(ctx, reg.db, "asset", xpubs, quorum, clientToken)
+       _, assetSigner, err := signers.Create("asset", xpubs, quorum)
        if err != nil {
                return nil, err
        }
index c22211a..cbe89e0 100644 (file)
@@ -18,7 +18,7 @@ import (
 func TestDefineAsset(t *testing.T) {
        ctx := context.Background()
        reg := mockNewRegistry(t)
-       asset, err := reg.Define(ctx, []chainkd.XPub{testutil.TestXPub}, 1, nil, "asset-alias", nil, "")
+       asset, err := reg.Define([]chainkd.XPub{testutil.TestXPub}, 1, nil, "asset-alias", nil)
        if err != nil {
                testutil.FatalErr(t, err)
        }
@@ -37,7 +37,7 @@ func TestFindAssetByID(t *testing.T) {
        ctx := context.Background()
        reg := mockNewRegistry(t)
        keys := []chainkd.XPub{testutil.TestXPub}
-       asset, err := reg.Define(ctx, keys, 1, nil, "", nil, "")
+       asset, err := reg.Define(keys, 1, nil, "", nil)
        if err != nil {
                testutil.FatalErr(t, err)
 
index 16cd20c..6a1c03a 100644 (file)
@@ -5,7 +5,6 @@ import (
 
        "github.com/bytom/blockchain/asset"
        "github.com/bytom/crypto/ed25519/chainkd"
-       "github.com/bytom/net/http/reqid"
 
        log "github.com/sirupsen/logrus"
 )
@@ -17,36 +16,26 @@ func (bcr *BlockchainReactor) createAsset(ctx context.Context, ins struct {
        Quorum     int                    `json:"quorum"`
        Definition map[string]interface{} `json:"definition"`
        Tags       map[string]interface{} `json:"tags"`
-
-       // ClientToken is the application's unique token for the asset. Every asset
-       // should have a unique client token. The client token is used to ensure
-       // idempotency of create asset requests. Duplicate create asset requests
-       // with the same client_token will only create one asset.
-       AccessToken string `json:"access_token"`
 }) Response {
-       subctx := reqid.NewSubContext(ctx, reqid.New())
-
        ass, err := bcr.assets.Define(
-               subctx,
                ins.RootXPubs,
                ins.Quorum,
                ins.Definition,
                ins.Alias,
                ins.Tags,
-               ins.AccessToken,
        )
        if err != nil {
-               return resWrapper(nil, err)
+               return NewErrorResponse(err)
        }
 
        annotatedAsset, err := asset.Annotated(ass)
        if err != nil {
-               return resWrapper(nil, err)
+               return NewErrorResponse(err)
        }
 
        log.WithField("asset ID", annotatedAsset.ID.String()).Info("Created asset")
 
-       return resWrapper(annotatedAsset)
+       return NewSuccessResponse(annotatedAsset)
 }
 
 // POST /update-asset-tags
index 2d96fd0..4eee951 100755 (executable)
@@ -59,11 +59,11 @@ func TestHSM(t *testing.T) {
                t.Fatal(err)
        }
 
-       acct1, err := accounts.Create(ctx, []chainkd.XPub{xpub1.XPub}, 1, "acc1", nil, "")
+       acct1, err := accounts.Create([]chainkd.XPub{xpub1.XPub}, 1, "acc1", nil)
        if err != nil {
                t.Fatal(err)
        }
-       acct2, err := accounts.Create(ctx, []chainkd.XPub{xpub2.XPub}, 1, "acc2", nil, "")
+       acct2, err := accounts.Create([]chainkd.XPub{xpub2.XPub}, 1, "acc2", nil)
        if err != nil {
                t.Fatal(err)
        }
@@ -71,11 +71,11 @@ func TestHSM(t *testing.T) {
        assetDef1 := map[string]interface{}{"foo": 1}
        assetDef2 := map[string]interface{}{"foo": 2}
 
-       asset1, err := assets.Define(ctx, []chainkd.XPub{xpub1.XPub}, 1, assetDef1, "foo1", nil, "")
+       asset1, err := assets.Define([]chainkd.XPub{xpub1.XPub}, 1, assetDef1, "foo1", nil)
        if err != nil {
                t.Fatal(err)
        }
-       asset2, err := assets.Define(ctx, []chainkd.XPub{xpub2.XPub}, 1, assetDef2, "foo2", nil, "")
+       asset2, err := assets.Define([]chainkd.XPub{xpub2.XPub}, 1, assetDef2, "foo2", nil)
        if err != nil {
                t.Fatal(err)
        }
index b748348..7fe5cf6 100755 (executable)
@@ -67,7 +67,7 @@ func Path(s *Signer, ks keySpace, itemIndexes ...uint64) [][]byte {
 }
 
 // Create creates and stores a Signer in the database
-func Create(ctx context.Context, db dbm.DB, signerType string, xpubs []chainkd.XPub, quorum int, clientToken string) (string, *Signer, error) {
+func Create(signerType string, xpubs []chainkd.XPub, quorum int) (string, *Signer, error) {
        if len(xpubs) == 0 {
                return "", nil, errors.Wrap(ErrNoXPubs)
        }
@@ -83,12 +83,6 @@ func Create(ctx context.Context, db dbm.DB, signerType string, xpubs []chainkd.X
                return "", nil, errors.Wrap(ErrBadQuorum)
        }
 
-       var xpubBytes [][]byte
-       for _, key := range xpubs {
-               key := key
-               xpubBytes = append(xpubBytes, key[:])
-       }
-
        id, keyIndex := IdGenerate()
        return id, &Signer{
                Type:     signerType,
index 9d27997..f476d58 100755 (executable)
@@ -173,7 +173,7 @@ func (w *Wallet) ImportAccountPrivKey(hsm *pseudohsm.HSM, xprv chainkd.XPrv, ali
        if err != nil {
                return nil, err
        }
-       newAccount, err := w.AccountMgr.Create(nil, []chainkd.XPub{xpub.XPub}, SINGLE, alias, nil, "")
+       newAccount, err := w.AccountMgr.Create([]chainkd.XPub{xpub.XPub}, SINGLE, alias, nil)
        if err != nil {
                return nil, err
        }
index eded02a..543e224 100644 (file)
@@ -41,7 +41,7 @@ func TestP2PKH(t *testing.T) {
                t.Fatal(err)
        }
 
-       testAccount, err := accountManager.Create(nil, []chainkd.XPub{xpub.XPub}, 1, "testAccount", nil, "")
+       testAccount, err := accountManager.Create([]chainkd.XPub{xpub.XPub}, 1, "testAccount", nil)
        if err != nil {
                t.Fatal(err)
        }
@@ -97,7 +97,7 @@ func TestP2SH(t *testing.T) {
                t.Fatal(err)
        }
 
-       testAccount, err := accountManager.Create(nil, []chainkd.XPub{xpub1.XPub, xpub2.XPub}, 2, "testAccount", nil, "")
+       testAccount, err := accountManager.Create([]chainkd.XPub{xpub1.XPub, xpub2.XPub}, 2, "testAccount", nil)
        if err != nil {
                t.Fatal(err)
        }