9 log "github.com/sirupsen/logrus"
11 "github.com/bytom/blockchain/signers"
12 "github.com/bytom/blockchain/txbuilder"
13 chainjson "github.com/bytom/encoding/json"
14 "github.com/bytom/protocol/bc"
15 "github.com/bytom/protocol/bc/legacy"
18 //NewIssueAction create a new asset issue action
19 func (reg *Registry) NewIssueAction(assetAmount bc.AssetAmount, referenceData chainjson.Map) txbuilder.Action {
22 AssetAmount: assetAmount,
23 ReferenceData: referenceData,
27 //DecodeIssueAction unmarshal JSON-encoded data of asset issue action
28 func (reg *Registry) DecodeIssueAction(data []byte) (txbuilder.Action, error) {
29 a := &issueAction{assets: reg}
30 err := json.Unmarshal(data, a)
34 type issueAction struct {
37 ReferenceData chainjson.Map `json:"reference_data"`
40 func (a *issueAction) Build(ctx context.Context, builder *txbuilder.TemplateBuilder) error {
41 if a.AssetId.IsZero() {
42 return txbuilder.MissingFieldsError("asset_id")
45 asset, err := a.assets.findByID(ctx, a.AssetId)
51 _, err = rand.Read(nonce[:])
56 assetDef := asset.RawDefinition()
58 txin := legacy.NewIssuanceInput(nonce[:], a.Amount, a.ReferenceData, asset.InitialBlockHash, asset.IssuanceProgram, nil, assetDef)
60 tplIn := &txbuilder.SigningInstruction{}
61 path := signers.Path(asset.Signer, signers.AssetKeySpace)
62 tplIn.AddWitnessKeys(asset.Signer.XPubs, path, asset.Signer.Quorum)
64 log.Info("Issue action build")
65 builder.RestrictMinTime(time.Now())
66 return builder.AddInput(txin, tplIn)