9 log "github.com/sirupsen/logrus"
11 "github.com/vapor/blockchain/signers"
12 "github.com/vapor/blockchain/txbuilder"
13 "github.com/vapor/protocol/bc"
14 "github.com/vapor/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 {
35 Arguments []txbuilder.ContractArgument `json:"arguments"`
38 func (a *issueAction) Build(ctx context.Context, builder *txbuilder.TemplateBuilder) error {
39 if a.AssetId.IsZero() {
40 return txbuilder.MissingFieldsError("asset_id")
43 asset, err := a.assets.FindByID(ctx, a.AssetId)
49 _, err = rand.Read(nonce[:])
54 txin := types.NewIssuanceInput(nonce[:], a.Amount, asset.IssuanceProgram, nil, asset.RawDefinitionByte)
55 tplIn := &txbuilder.SigningInstruction{}
56 if asset.Signer != nil {
57 path := signers.GetBip0032Path(asset.Signer, signers.AssetKeySpace)
58 tplIn.AddRawWitnessKeys(asset.Signer.XPubs, path, asset.Signer.Quorum)
59 } else if a.Arguments != nil {
60 if err := txbuilder.AddContractArgs(tplIn, a.Arguments); err != nil {
65 log.Info("Issue action build")
66 builder.RestrictMinTime(time.Now())
67 return builder.AddInput(txin, tplIn)
70 func (a *issueAction) ActionType() string {