package test
import (
- "crypto/rand"
"encoding/json"
"fmt"
"time"
- "github.com/vapor/account"
- "github.com/vapor/asset"
- "github.com/vapor/blockchain/pseudohsm"
- "github.com/vapor/blockchain/signers"
- "github.com/vapor/blockchain/txbuilder"
- "github.com/vapor/common"
- "github.com/vapor/consensus"
- "github.com/vapor/crypto/ed25519/chainkd"
- "github.com/vapor/crypto/sha3pool"
- dbm "github.com/vapor/database/leveldb"
- "github.com/vapor/errors"
- "github.com/vapor/protocol/bc"
- "github.com/vapor/protocol/bc/types"
- "github.com/vapor/protocol/vm"
- "github.com/vapor/protocol/vm/vmutil"
+ "github.com/bytom/vapor/account"
+ "github.com/bytom/vapor/asset"
+ "github.com/bytom/vapor/blockchain/pseudohsm"
+ "github.com/bytom/vapor/blockchain/signers"
+ "github.com/bytom/vapor/blockchain/txbuilder"
+ "github.com/bytom/vapor/common"
+ "github.com/bytom/vapor/consensus"
+ "github.com/bytom/vapor/crypto/ed25519/chainkd"
+ "github.com/bytom/vapor/crypto/sha3pool"
+ "github.com/bytom/vapor/database"
+ dbm "github.com/bytom/vapor/database/leveldb"
+ "github.com/bytom/vapor/errors"
+ "github.com/bytom/vapor/protocol/bc"
+ "github.com/bytom/vapor/protocol/bc/types"
+ "github.com/bytom/vapor/protocol/vm"
+ "github.com/bytom/vapor/protocol/vm/vmutil"
)
// TxGenerator used to generate new tx
return err
}
-func (g *TxGenerator) createAsset(accountAlias string, assetAlias string) (*asset.Asset, error) {
- acc, err := g.AccountManager.FindByAlias(accountAlias)
- if err != nil {
- return nil, err
- }
- return g.Assets.Define(acc.XPubs, len(acc.XPubs), nil, 0, assetAlias, nil)
-}
-
func (g *TxGenerator) mockUtxo(accountAlias, assetAlias string, amount uint64) (*account.UTXO, error) {
ctrlProg, err := g.createControlProgram(accountAlias, false)
if err != nil {
return g.AddTxInput(txInput, signInst)
}
-// AddIssuanceInput add a issue input
-func (g *TxGenerator) AddIssuanceInput(assetAlias string, amount uint64) error {
- asset, err := g.Assets.FindByAlias(assetAlias)
- if err != nil {
- return err
- }
-
- var nonce [8]byte
- _, err = rand.Read(nonce[:])
- if err != nil {
- return err
- }
- issuanceInput := types.NewIssuanceInput(nonce[:], amount, asset.IssuanceProgram, nil, asset.RawDefinitionByte)
- signInstruction := &txbuilder.SigningInstruction{}
- path := signers.GetBip0032Path(asset.Signer, signers.AssetKeySpace)
- signInstruction.AddRawWitnessKeys(asset.Signer.XPubs, path, asset.Signer.Quorum)
- g.Builder.RestrictMinTime(time.Now())
- return g.Builder.AddInput(issuanceInput, signInstruction)
-}
-
// AddTxOutput add a tx output
func (g *TxGenerator) AddTxOutput(accountAlias, assetAlias string, amount uint64) error {
assetAmount, err := g.assetAmount(assetAlias, uint64(amount))
cp := account.CtrlProgram{}
var hash [32]byte
sha3pool.Sum256(hash[:], input.ControlProgram)
- bytes := db.Get(account.ContractKey(hash))
+ bytes := db.Get(database.ContractKey(bc.NewHash(hash)))
if bytes == nil {
return nil, fmt.Errorf("can't find CtrlProgram for the SpendInput")
}