mirror of
https://github.com/luxfi/utxo.git
synced 2026-11-02 15:37:17 +00:00
- Fix ids.ToShortID multi-value error in mldsafx - Add runtime v1.0.1 dependency - Update transferables for consensus compatibility
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package secp256k1fx
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/luxfi/runtime"
|
|
"github.com/luxfi/vm/components/verify"
|
|
)
|
|
|
|
var (
|
|
_ verify.State = (*TransferOutput)(nil)
|
|
|
|
ErrNoValueOutput = errors.New("output has no value")
|
|
)
|
|
|
|
type TransferOutput struct {
|
|
verify.IsState `serialize:"-" json:"-"`
|
|
|
|
Amt uint64 `serialize:"true" json:"amount"`
|
|
|
|
OutputOwners `serialize:"true"`
|
|
}
|
|
|
|
func (out *TransferOutput) InitializeWithContext(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
// InitRuntime sets the context for address formatting
|
|
func (out *TransferOutput) InitRuntime(rt *runtime.Runtime) {
|
|
out.OutputOwners.InitRuntime(rt)
|
|
}
|
|
|
|
// MarshalJSON marshals Amt and the embedded OutputOwners struct
|
|
// into a JSON readable format
|
|
// If OutputOwners cannot be serialized then this will return error
|
|
func (out *TransferOutput) MarshalJSON() ([]byte, error) {
|
|
result, err := out.OutputOwners.Fields()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result["amount"] = out.Amt
|
|
return json.Marshal(result)
|
|
}
|
|
|
|
// Amount returns the quantity of the asset this output consumes
|
|
func (out *TransferOutput) Amount() uint64 {
|
|
return out.Amt
|
|
}
|
|
|
|
func (out *TransferOutput) Verify() error {
|
|
switch {
|
|
case out == nil:
|
|
return ErrNilOutput
|
|
case out.Amt == 0:
|
|
return ErrNoValueOutput
|
|
default:
|
|
return out.OutputOwners.Verify()
|
|
}
|
|
}
|
|
|
|
func (out *TransferOutput) Owners() interface{} {
|
|
return &out.OutputOwners
|
|
}
|
|
|
|
func (*TransferOutput) isState() {}
|