Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Apr 10, 2019
1 parent 8556e9f commit 559a382
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/gofs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ func Pin(ctx context.Context, rpcURL string, contract common.Address, pk *ecdsa.
case types.ReceiptStatusFailed:
return fmt.Errorf("tx %s failed", h.Hex())
case types.ReceiptStatusSuccessful:
fmt.Printf("Purchased %d GigaByte Hours of storage for %s.\n", dur, ci)
fmt.Printf(`https://testnet-explorer.gochain.io/tx/%s`, h.Hex())
fmt.Printf("Purchased %d GigaByteHours of storage for %s.\n", dur, ci)
fmt.Printf("https://testnet-explorer.gochain.io/tx/%s\n", h.Hex())
return nil
default:
return fmt.Errorf("tx %s unrecognized receipt status: %d", h.Hex(), r.Status)
Expand Down
14 changes: 9 additions & 5 deletions gofs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gofs

import (
"bytes"
"context"
"crypto/ecdsa"
"errors"
Expand All @@ -23,7 +24,7 @@ import (

var (
pinnerABI abi.ABI
pinInputs abi.Arguments
pinMethod abi.Method
)

func init() {
Expand All @@ -32,7 +33,7 @@ func init() {
panic(fmt.Sprintf("failed to parse generated abi: %v", err))
}
pinnerABI = parsed
pinInputs = pinnerABI.Methods["pin"].Inputs
pinMethod = pinnerABI.Methods["pin"]
}

func Rate(ctx context.Context, rpcURL string, contract common.Address) (*big.Int, error) {
Expand Down Expand Up @@ -157,12 +158,15 @@ type EventFilter struct {
}

type PinInputs struct {
CID []byte
GBH *big.Int
CID []byte `abi:"cid"`
GBH *big.Int `abi:"gbh"`
}

// UnpackPinInputs returns arguments from a pin call.
// Handles full tx data, or plain inputs.
func UnpackPinInputs(data []byte) (pi PinInputs, err error) {
err = pinInputs.Unpack(&pinInputs, data)
data = bytes.TrimPrefix(data, pinMethod.Id())
err = pinMethod.Inputs.Unpack(&pi, data)
return
}

Expand Down
37 changes: 37 additions & 0 deletions gofs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gofs

import (
"bytes"
"math/big"
"testing"
)

func TestUnpackPinInputs(t *testing.T) {
cid, gbh := []byte("test"), big.NewInt(10)
data, err := pinMethod.Inputs.Pack(cid, gbh)
if err != nil {
t.Fatal(err)
}

pi, err := UnpackPinInputs(data)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(cid, pi.CID) {
t.Error("cid wrong")
}
if pi.GBH.Cmp(gbh) != 0 {
t.Error("gbh wrong")
}

pi, err = UnpackPinInputs(append(pinMethod.Id(), data...))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(cid, pi.CID) {
t.Error("cid wrong")
}
if pi.GBH.Cmp(gbh) != 0 {
t.Error("gbh wrong")
}
}

0 comments on commit 559a382

Please sign in to comment.