OSDN Git Service

add arbitrary for retire (#1065)
authorDerek <shanhu5739@gmail.com>
Wed, 20 Jun 2018 10:15:57 +0000 (18:15 +0800)
committerPaladz <yzhu101@uottawa.ca>
Wed, 20 Jun 2018 10:15:57 +0000 (18:15 +0800)
* add rescan-blocks api

* rename rescan-blocks to rescan-wallet

* rename rescanWallet to rescanWallet

* add arbitrary for retire

* retireAction needs a program

* retireAction used address

* add RetireProgram for script

* update RetireProgram for script

blockchain/txbuilder/actions.go
protocol/vm/vmutil/script.go

index 996c01e..525f11c 100644 (file)
@@ -132,6 +132,7 @@ func DecodeRetireAction(data []byte) (Action, error) {
 
 type retireAction struct {
        bc.AssetAmount
+       Arbitrary json.HexBytes `json:"arbitrary"`
 }
 
 func (a *retireAction) Build(ctx context.Context, b *TemplateBuilder) error {
@@ -146,6 +147,10 @@ func (a *retireAction) Build(ctx context.Context, b *TemplateBuilder) error {
                return MissingFieldsError(missing...)
        }
 
-       out := types.NewTxOutput(*a.AssetId, a.Amount, retirementProgram)
+       program, err := vmutil.RetireProgram(a.Arbitrary)
+       if err != nil {
+               return err
+       }
+       out := types.NewTxOutput(*a.AssetId, a.Amount, program)
        return b.AddOutput(out)
 }
index 57bea29..314c4c6 100644 (file)
@@ -55,6 +55,16 @@ func P2WSHProgram(hash []byte) ([]byte, error) {
        return builder.Build()
 }
 
+// RetireProgram generates the script for retire output
+func RetireProgram(comment []byte) ([]byte, error) {
+       builder := NewBuilder()
+       builder.AddOp(vm.OP_FAIL)
+       if len(comment) != 0 {
+               builder.AddData(comment)
+       }
+       return builder.Build()
+}
+
 // P2PKHSigProgram generates the script for control with pubkey hash
 func P2PKHSigProgram(pubkeyHash []byte) ([]byte, error) {
        builder := NewBuilder()