forked from EpiK-Protocol/go-epik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
360 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package remotewallet | ||
|
||
import ( | ||
"context" | ||
"go.uber.org/fx" | ||
"golang.org/x/xerrors" | ||
"net/http" | ||
|
||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/api/client" | ||
"github.com/filecoin-project/lotus/node/modules/helpers" | ||
) | ||
|
||
type RemoteWallet struct { | ||
api.WalletAPI | ||
} | ||
|
||
func SetupRemoteWallet(url string) func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) { | ||
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) { | ||
/*sp := strings.SplitN(env, ":", 2) | ||
if len(sp) != 2 { | ||
log.Warnf("invalid env(%s) value, missing token or address", envKey) | ||
} else { | ||
ma, err := multiaddr.NewMultiaddr(sp[1]) | ||
if err != nil { | ||
return APIInfo{}, xerrors.Errorf("could not parse multiaddr from env(%s): %w", envKey, err) | ||
} | ||
return APIInfo{ | ||
Addr: ma, | ||
Token: []byte(sp[0]), | ||
}, nil | ||
}*/ | ||
|
||
headers := http.Header{} | ||
/*headers.Add("Authorization", "Bearer "+token)*/ | ||
|
||
wapi, closer, err := client.NewWalletRPC(mctx, url, headers) | ||
if err != nil { | ||
return nil, xerrors.Errorf("creating jsonrpc client: %w", err) | ||
} | ||
|
||
lc.Append(fx.Hook{ | ||
OnStop: func(ctx context.Context) error { | ||
closer() | ||
return nil | ||
}, | ||
}) | ||
|
||
return &RemoteWallet{wapi}, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/specs-actors/actors/crypto" | ||
|
||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
) | ||
|
||
type LoggedWallet struct { | ||
under api.WalletAPI | ||
} | ||
|
||
func (c *LoggedWallet) WalletNew(ctx context.Context, typ crypto.SigType) (address.Address, error) { | ||
n, err := typ.Name() | ||
if err != nil { | ||
return address.Address{}, err | ||
} | ||
|
||
log.Infow("WalletNew", "type", n) | ||
|
||
return c.under.WalletNew(ctx, typ) | ||
} | ||
|
||
func (c *LoggedWallet) WalletHas(ctx context.Context, addr address.Address) (bool, error) { | ||
log.Infow("WalletHas", "address", addr) | ||
|
||
return c.under.WalletHas(ctx, addr) | ||
} | ||
|
||
func (c *LoggedWallet) WalletList(ctx context.Context) ([]address.Address, error) { | ||
log.Infow("WalletList") | ||
|
||
return c.under.WalletList(ctx) | ||
} | ||
|
||
func (c *LoggedWallet) WalletSign(ctx context.Context, k address.Address, msg []byte) (*crypto.Signature, error) { | ||
log.Infow("WalletSign", "address", k) | ||
|
||
return c.under.WalletSign(ctx, k, msg) | ||
} | ||
|
||
func (c *LoggedWallet) WalletSignMessage(ctx context.Context, k address.Address, msg *types.Message) (*types.SignedMessage, error) { | ||
log.Infow("WalletSignMessage", "address", k) | ||
|
||
return c.under.WalletSignMessage(ctx, k, msg) | ||
} | ||
|
||
func (c *LoggedWallet) WalletExport(ctx context.Context, a address.Address) (*types.KeyInfo, error) { | ||
log.Infow("WalletExport", "address", a) | ||
|
||
return c.under.WalletExport(ctx, a) | ||
} | ||
|
||
func (c *LoggedWallet) WalletImport(ctx context.Context, ki *types.KeyInfo) (address.Address, error) { | ||
log.Infow("WalletImport", "type", ki.Type) | ||
|
||
return c.under.WalletImport(ctx, ki) | ||
} | ||
|
||
func (c *LoggedWallet) WalletDelete(ctx context.Context, addr address.Address) error { | ||
log.Infow("WalletDelete", "address", addr) | ||
|
||
return c.under.WalletDelete(ctx, addr) | ||
} |
Oops, something went wrong.