2019-08-09 21:41:50 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2019-09-09 13:59:07 +00:00
|
|
|
"bytes"
|
2019-08-13 04:27:54 +00:00
|
|
|
"encoding/base64"
|
|
|
|
|
2019-12-19 20:28:17 +00:00
|
|
|
cborrpc "github.com/filecoin-project/go-cbor-util"
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2019-08-09 21:41:50 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SignedVoucher struct {
|
|
|
|
TimeLock uint64
|
|
|
|
SecretPreimage []byte
|
|
|
|
Extra *ModVerifyParams
|
|
|
|
Lane uint64
|
|
|
|
Nonce uint64
|
|
|
|
Amount BigInt
|
|
|
|
MinCloseHeight uint64
|
|
|
|
|
|
|
|
Merges []Merge
|
|
|
|
|
|
|
|
Signature *Signature
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sv *SignedVoucher) SigningBytes() ([]byte, error) {
|
|
|
|
osv := *sv
|
|
|
|
osv.Signature = nil
|
2019-09-10 23:03:17 +00:00
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := osv.MarshalCBOR(buf); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf.Bytes(), nil
|
2019-08-09 21:41:50 +00:00
|
|
|
}
|
|
|
|
|
2019-08-13 04:27:54 +00:00
|
|
|
func (sv *SignedVoucher) EncodedString() (string, error) {
|
2019-09-10 23:03:17 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := sv.MarshalCBOR(buf); err != nil {
|
2019-08-13 04:27:54 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2019-09-10 23:03:17 +00:00
|
|
|
return base64.RawURLEncoding.EncodeToString(buf.Bytes()), nil
|
2019-08-13 04:27:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 13:59:07 +00:00
|
|
|
func (sv *SignedVoucher) Equals(other *SignedVoucher) bool {
|
|
|
|
// TODO: make this less bad
|
|
|
|
|
2019-11-05 03:42:13 +00:00
|
|
|
selfB, err := cborrpc.Dump(sv)
|
2019-09-09 13:59:07 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("SignedVoucher.Equals: dump self: %s", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-11-05 03:42:13 +00:00
|
|
|
otherB, err := cborrpc.Dump(other)
|
2019-09-09 13:59:07 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("SignedVoucher.Equals: dump other: %s", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes.Equal(selfB, otherB)
|
|
|
|
}
|
|
|
|
|
2019-08-13 04:27:54 +00:00
|
|
|
func DecodeSignedVoucher(s string) (*SignedVoucher, error) {
|
|
|
|
data, err := base64.RawURLEncoding.DecodeString(s)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var sv SignedVoucher
|
|
|
|
if err := cbor.DecodeInto(data, &sv); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &sv, nil
|
|
|
|
}
|
|
|
|
|
2019-08-09 21:41:50 +00:00
|
|
|
type Merge struct {
|
|
|
|
Lane uint64
|
|
|
|
Nonce uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type ModVerifyParams struct {
|
|
|
|
Actor address.Address
|
|
|
|
Method uint64
|
|
|
|
Data []byte
|
|
|
|
}
|