Skip to content

Commit

Permalink
move gbh from input to event
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Apr 29, 2019
1 parent 4d90882 commit b5bb611
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 49 deletions.
9 changes: 5 additions & 4 deletions contracts/GOFSPinner.abi
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
{
"name": "cid",
"type": "bytes"
},
{
"name": "gbh",
"type": "uint256"
}
],
"name": "pin",
Expand Down Expand Up @@ -92,6 +88,11 @@
"indexed": true,
"name": "cid",
"type": "bytes"
},
{
"indexed": false,
"name": "gbh",
"type": "uint256"
}
],
"name": "Pinned",
Expand Down
2 changes: 1 addition & 1 deletion contracts/GOFSPinner.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x608060405234801561001057600080fd5b506040516020806105028339810180604052602081101561003057600080fd5b505160008054600160a060020a03191633179055600155436002556104a88061005a6000396000f3fe60806040526004361061005b577c010000000000000000000000000000000000000000000000000000000060003504632c4e722e811461006057806334fcf4371461008757806393b862fe146100c5578063f905c15a1461016d575b600080fd5b34801561006c57600080fd5b50610075610182565b60408051918252519081900360200190f35b34801561009357600080fd5b506100b1600480360360208110156100aa57600080fd5b5035610188565b604080519115158252519081900360200190f35b6100b1600480360360408110156100db57600080fd5b8101906020810181356401000000008111156100f657600080fd5b82018360208201111561010857600080fd5b8035906020019184600183028401116401000000008311171561012a57600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955050913592506101eb915050565b34801561017957600080fd5b50610075610454565b60015481565b6000805473ffffffffffffffffffffffffffffffffffffffff1633146101e25760405160e560020a62461bcd02815260040180806020018281038252602281526020018061045b6022913960400191505060405180910390fd5b60019190915590565b60008260008151811015156101fc57fe5b90602001015160f860020a900460f860020a027effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916601260f860020a0214801561028f575082600181518110151561025057fe5b90602001015160f860020a900460f860020a027effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916602060f860020a02145b156102e4576040805160e560020a62461bcd02815260206004820152601a60248201527f56657273696f6e203020434944206e6f7420616c6c6f7765642e000000000000604482015290519081900360640190fd5b6000821161033c576040805160e560020a62461bcd02815260206004820152601a60248201527f43616e6e6f7420707572636861736520302073746f726167652e000000000000604482015290519081900360640190fd5b600154820234811115610399576040805160e560020a62461bcd02815260206004820152600e60248201527f56616c756520746f6f206c6f772e000000000000000000000000000000000000604482015290519081900360640190fd5b60405133903483900380156108fc02916000818181858888f193505050501580156103c8573d6000803e3d6000fd5b50836040518082805190602001908083835b602083106103f95780518252601f1990920191602091820191016103da565b5181516020939093036101000a60001901801990911692169190911790526040519201829003822093503392507f6f488ce79215cfcbd7d03c6e0cf105b3d9ee23884121bebe21744e7a38fc13b29160009150a35092915050565b6002548156fe4f6e6c79206f776e65722063616e2063616c6c20746869732066756e6374696f6e2ea165627a7a72305820b9cd700d5d036db00e45952785bac138dae364751a9a2dab7f347852ae65f3410029
0x608060405234801561001057600080fd5b506040516020806104d38339810180604052602081101561003057600080fd5b505160008054600160a060020a03191633179055600155436002556104798061005a6000396000f3fe60806040526004361061005b577c010000000000000000000000000000000000000000000000000000000060003504632c4e722e811461006057806334fcf437146100875780637d1962f8146100c5578063f905c15a1461016b575b600080fd5b34801561006c57600080fd5b50610075610180565b60408051918252519081900360200190f35b34801561009357600080fd5b506100b1600480360360208110156100aa57600080fd5b5035610186565b604080519115158252519081900360200190f35b6100b1600480360360208110156100db57600080fd5b8101906020810181356401000000008111156100f657600080fd5b82018360208201111561010857600080fd5b8035906020019184600183028401116401000000008311171561012a57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610200945050505050565b34801561017757600080fd5b50610075610425565b60015481565b6000805473ffffffffffffffffffffffffffffffffffffffff1633146101f7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061042c6022913960400191505060405180910390fd5b60019190915590565b600081600081518110151561021157fe5b90602001015160f860020a900460f860020a027effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916601260f860020a021480156102a4575081600181518110151561026557fe5b90602001015160f860020a900460f860020a027effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916602060f860020a02145b1561031057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f56657273696f6e203020434944206e6f7420616c6c6f7765642e000000000000604482015290519081900360640190fd5b60015434101561038157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f43616e6e6f7420707572636861736520302073746f726167652e000000000000604482015290519081900360640190fd5b60006001543481151561039057fe5b049050826040518082805190602001908083835b602083106103c35780518252601f1990920191602091820191016103a4565b51815160209384036101000a60001901801990921691161790526040805192909401829003822087835293519395503394507f7c80eb99758dfe3e8aef5df583c1c9bab5369cf46b930b802f130edcfeac90ca9391829003019150a350919050565b6002548156fe4f6e6c79206f776e65722063616e2063616c6c20746869732066756e6374696f6e2ea165627a7a7230582066a562655974347c7be5c07036895dbda69fb0afe99bdcb6d150fa1322d3610c0029
9 changes: 5 additions & 4 deletions contracts/Pinner.abi
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
{
"name": "cid",
"type": "bytes"
},
{
"name": "gbh",
"type": "uint256"
}
],
"name": "pin",
Expand Down Expand Up @@ -62,6 +58,11 @@
"indexed": true,
"name": "cid",
"type": "bytes"
},
{
"indexed": false,
"name": "gbh",
"type": "uint256"
}
],
"name": "Pinned",
Expand Down
2 changes: 1 addition & 1 deletion contracts/owned.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x6080604052348015600f57600080fd5b5060008054600160a060020a03191633179055603580602f6000396000f3fe6080604052600080fdfea165627a7a72305820222698464b5b1fd5724a52f1e8dfa9f66090fc44c9d0ec3a80c5cd0dd570ee7a0029
0x6080604052348015600f57600080fd5b5060008054600160a060020a03191633179055603580602f6000396000f3fe6080604052600080fdfea165627a7a7230582098afa05ed8e3ff8058a574fc21b8e95b17963ede9b523afa7131a098db58c42f0029
22 changes: 7 additions & 15 deletions contracts/pinner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ interface Pinner {
// Returns the number of the block when this contract was deployed.
function deployed() external view returns (uint);

// Pin a CID. gbh must be greater than 0. CID must not be version 0.
function pin(bytes calldata cid, uint gbh) external payable returns (bool);
// Pin a CID. Value must be greater than 0. CID must not be version 0.
function pin(bytes calldata cid) external payable returns (bool);

event Pinned(address indexed user, bytes indexed cid);
event Pinned(address indexed user, bytes indexed cid, uint gbh);
}


contract owned {
constructor() public { owner = msg.sender; }
address payable owner;
Expand Down Expand Up @@ -50,23 +49,16 @@ contract GOFSPinner is Pinner, owned {
}

//TODO calculate and document gas usage
// transfer: 2300 gas
function pin(bytes memory cid, uint gbh) public payable returns (bool) {
function pin(bytes memory cid) public payable returns (bool) {
require(
!(cid[0] == 0x12 && cid[1] == 0x20),
"Version 0 CID not allowed."
);
require(
gbh > 0,
msg.value >= rate,
"Cannot purchase 0 storage."
);
uint cost = gbh*rate;
require(
msg.value >= cost,
"Value too low."
);
// refund excess
msg.sender.transfer(msg.value - cost);
emit Pinned(msg.sender, cid);
uint gbh = msg.value/rate;
emit Pinned(msg.sender, cid, gbh);
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf
github.com/aristanetworks/goarista v0.0.0-20190319235110-489128639c40 // indirect
github.com/gochain-io/gochain/v3 v3.1.14
github.com/gochain-io/web3 v0.0.36
github.com/gochain-io/web3 v0.1.2
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/ipfs/go-cid v0.0.1
github.com/pborman/uuid v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ github.com/gochain-io/gochain/v3 v3.0.11 h1:3ykaUoRnAFTPIw8ajnIb8e40ftR/Y267dKZW
github.com/gochain-io/gochain/v3 v3.0.11/go.mod h1:e+h1qGhr65M3MlO3kOnXRMXq6Btu8GJnOZWeCXauy9I=
github.com/gochain-io/gochain/v3 v3.1.14 h1:K9ktWBD8+oSJEi9ZOQVf/LvVS7a8qWrbrlMj3INnHdk=
github.com/gochain-io/gochain/v3 v3.1.14/go.mod h1:NbUyql/tzg4zjBiOW0kirbk7hvlBKO1Php4IaQQv47A=
github.com/gochain-io/web3 v0.0.36 h1:lKrRpXF/A2wVqONKJkKJadG1ZaiX6NDcQmI/6m0uCUg=
github.com/gochain-io/web3 v0.0.36/go.mod h1:YMqsKiDz8bpX8LnJEFgsK/RoJG+iE7T2NbUmbZxYPS0=
github.com/gochain-io/web3 v0.1.2 h1:CJa+Aqpvgs0zIrqhr31cuqlxyTkKF2nRWbu4z0xcLuE=
github.com/gochain-io/web3 v0.1.2/go.mod h1:YMqsKiDz8bpX8LnJEFgsK/RoJG+iE7T2NbUmbZxYPS0=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
Expand Down
7 changes: 3 additions & 4 deletions gofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func Pin(ctx context.Context, rpcURL string, contract common.Address, pk *ecdsa.
GasLimit: 50000,
Value: cost,
}
tx, err := p.Pin(opts, cid.Bytes(), big.NewInt(int64(dur)))
tx, err := p.Pin(opts, cid.Bytes())
if err != nil {
return common.Hash{}, nil, fmt.Errorf("failed to pin %q: %v", cid, err)
}
Expand Down Expand Up @@ -158,8 +158,7 @@ type EventFilter struct {
}

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

// UnpackPinInputs returns arguments from a pin call.
Expand Down Expand Up @@ -248,7 +247,7 @@ func Receipts(ctx context.Context, rpcURL string, contract common.Address, filte
receipts = append(receipts, Receipt{
User: from,
CID: ci,
GBH: pi.GBH,
GBH: event.Gbh,
Tx: tx,
BlNum: l.BlockNumber,
TxNum: l.TxIndex,
Expand Down
35 changes: 18 additions & 17 deletions pinner.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b5bb611

Please sign in to comment.