}
// 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)
}
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)
}
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)
}
}
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)
}
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)
}
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)
}
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
}
// 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
}
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
}
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)
}
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)
"github.com/bytom/blockchain/asset"
"github.com/bytom/crypto/ed25519/chainkd"
- "github.com/bytom/net/http/reqid"
log "github.com/sirupsen/logrus"
)
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
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)
}
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)
}
}
// 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)
}
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,
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
}
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)
}
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)
}