9 log "github.com/sirupsen/logrus"
11 "github.com/bytom/blockchain/signers"
12 "github.com/bytom/blockchain/txbuilder"
13 "github.com/bytom/protocol/bc"
14 "github.com/bytom/protocol/bc/types"
17 //NewIssueAction create a new asset issue action
18 func (reg *Registry) NewIssueAction(assetAmount bc.AssetAmount) txbuilder.Action {
21 AssetAmount: assetAmount,
25 //DecodeIssueAction unmarshal JSON-encoded data of asset issue action
26 func (reg *Registry) DecodeIssueAction(data []byte) (txbuilder.Action, error) {
27 a := &issueAction{assets: reg}
28 err := json.Unmarshal(data, a)
32 type issueAction struct {
37 func (a *issueAction) Build(ctx context.Context, builder *txbuilder.TemplateBuilder) error {
38 if a.AssetId.IsZero() {
39 return txbuilder.MissingFieldsError("asset_id")
42 asset, err := a.assets.FindByID(ctx, a.AssetId)
48 _, err = rand.Read(nonce[:])
53 assetDef := asset.RawDefinitionByte
55 txin := types.NewIssuanceInput(nonce[:], a.Amount, asset.IssuanceProgram, nil, assetDef)
57 tplIn := &txbuilder.SigningInstruction{}
58 path := signers.Path(asset.Signer, signers.AssetKeySpace)
59 tplIn.AddRawWitnessKeys(asset.Signer.XPubs, path, asset.Signer.Quorum)
61 log.Info("Issue action build")
62 builder.RestrictMinTime(time.Now())
63 return builder.AddInput(txin, tplIn)