2018-04-09 08:18:22 +00:00
|
|
|
package sign
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2018-06-06 07:35:32 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2018-04-09 08:18:22 +00:00
|
|
|
"github.com/pborman/uuid"
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/account"
|
2018-04-09 08:18:22 +00:00
|
|
|
)
|
|
|
|
|
2018-04-10 10:02:54 +00:00
|
|
|
// CompleteFunc is a function that is called after the sign request is approved.
|
2018-06-06 07:35:32 +00:00
|
|
|
type CompleteFunc func(account *account.SelectedExtKey, password string, completeArgs *TxArgs) (Response, error)
|
2018-04-09 08:18:22 +00:00
|
|
|
|
|
|
|
// Meta represents any metadata that could be attached to a signing request.
|
|
|
|
// It will be JSON-serialized and used in notifications to the API consumer.
|
|
|
|
type Meta interface{}
|
|
|
|
|
|
|
|
// Request is a single signing request.
|
|
|
|
type Request struct {
|
|
|
|
ID string
|
2018-04-10 10:02:54 +00:00
|
|
|
Method string
|
2018-04-09 08:18:22 +00:00
|
|
|
Meta Meta
|
|
|
|
context context.Context
|
|
|
|
locked bool
|
2018-04-10 10:02:54 +00:00
|
|
|
completeFunc CompleteFunc
|
2018-04-09 08:18:22 +00:00
|
|
|
result chan Result
|
|
|
|
}
|
|
|
|
|
2018-06-06 07:35:32 +00:00
|
|
|
// TxArgs represents the arguments to submit when signing a transaction
|
|
|
|
type TxArgs struct {
|
|
|
|
Gas *hexutil.Uint64 `json:"gas"`
|
|
|
|
GasPrice *hexutil.Big `json:"gasPrice"`
|
|
|
|
}
|
|
|
|
|
2018-04-10 10:02:54 +00:00
|
|
|
func newRequest(ctx context.Context, method string, meta Meta, completeFunc CompleteFunc) *Request {
|
2018-04-09 08:18:22 +00:00
|
|
|
return &Request{
|
|
|
|
ID: uuid.New(),
|
2018-04-10 10:02:54 +00:00
|
|
|
Method: method,
|
2018-04-09 08:18:22 +00:00
|
|
|
Meta: meta,
|
|
|
|
context: ctx,
|
|
|
|
locked: false,
|
|
|
|
completeFunc: completeFunc,
|
|
|
|
result: make(chan Result, 1),
|
|
|
|
}
|
|
|
|
}
|