Skip to content

Commit

Permalink
fix: build error
Browse files Browse the repository at this point in the history
  • Loading branch information
hunjixin committed Oct 21, 2022
1 parent fd9270b commit 58b843d
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 77 deletions.
2 changes: 1 addition & 1 deletion examples/erc20/client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {
val := big.NewInt(1000)
req := contract.FakeSetBalance{
Addr: addr,
Balance: &val,
Balance: val,
}
err = ercClient.FakeSetBalance(ctx, &req)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions examples/hellocontract/client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func main() {
log.Fatalln(err)
return
}
ercClient := client.NewStateClient(v0FullNode, client.SetFromAddressOpt(addr))
helloClient := client.NewStateClient(v0FullNode, client.SetFromAddressOpt(addr))

code, err := ioutil.ReadFile("../hellocontract.wasm")
if err != nil {
log.Fatalln(err)
return
}

installRet, err := ercClient.Install(ctx, code)
installRet, err := helloClient.Install(ctx, code)
if err != nil {
log.Fatalln(err)
return
Expand All @@ -52,14 +52,14 @@ func main() {
return
}

execRet, err := ercClient.CreateActor(ctx, installRet.CodeCid, createParams)
execRet, err := helloClient.CreateActor(ctx, installRet.CodeCid, createParams)
if err != nil {
log.Fatalln(err)
return
}
println("actor id", execRet.IDAddress.String())

ret, err := ercClient.SayHello(ctx)
ret, err := helloClient.SayHello(ctx)
if err != nil {
log.Fatalln(err)
return
Expand Down
35 changes: 35 additions & 0 deletions sdk/sys/simulated/ipld.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package simulated

import (
"github.com/ipfs-force-community/go-fvm-sdk/sdk/types"
"github.com/ipfs/go-cid"
)

func (fvmSimulator *FvmSimulator) Open(id cid.Cid) (*types.IpldOpen, error) {
blockid, blockstat := fvmSimulator.blockOpen(id)
return &types.IpldOpen{ID: blockid, Size: blockstat.size, Codec: blockstat.codec}, nil
}

func (fvmSimulator *FvmSimulator) Create(codec uint64, data []byte) (uint32, error) {
index := fvmSimulator.blockCreate(codec, data)
return index, nil
}

func (fvmSimulator *FvmSimulator) Read(id uint32, offset, size uint32) ([]byte, uint32, error) {
data, err := fvmSimulator.blockRead(id, offset)
if err != nil {
return nil, 0, err
}
if size < uint32(len(data)) {
return data[:size], uint32(len(data)) - size, nil
}
return data, 0, nil
}

func (fvmSimulator *FvmSimulator) Stat(id uint32) (*types.IpldStat, error) {
return fvmSimulator.blockStat(id)
}

func (fvmSimulator *FvmSimulator) BlockLink(id uint32, hashFun uint64, hashLen uint32, cidBuf []byte) (cid.Cid, error) {
return fvmSimulator.blockLink(id, hashFun, hashLen)
}
11 changes: 11 additions & 0 deletions sdk/sys/simulated/rand.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package simulated

import "github.com/filecoin-project/go-state-types/abi"

func (fvmSimulator *FvmSimulator) GetChainRandomness(dst int64, round int64, entropy []byte) (abi.Randomness, error) {
return makeRandomness(dst, round, entropy), nil
}

func (fvmSimulator *FvmSimulator) GetBeaconRandomness(dst int64, round int64, entropy []byte) (abi.Randomness, error) {
return makeRandomness(dst, round, entropy), nil
}
73 changes: 2 additions & 71 deletions sdk/sys/simulated/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import (
"github.com/ipfs/go-cid"
)

func (fvmSimulator *FvmSimulator) Open(id cid.Cid) (*types.IpldOpen, error) {
blockid, blockstat := fvmSimulator.blockOpen(id)
return &types.IpldOpen{ID: blockid, Size: blockstat.size, Codec: blockstat.codec}, nil
}

func (fvmSimulator *FvmSimulator) GetActor(addr address.Address) (migration.Actor, error) {
fvmSimulator.actorLk.Lock()
defer fvmSimulator.actorLk.Unlock()
Expand All @@ -30,62 +25,6 @@ func (fvmSimulator *FvmSimulator) GetActor(addr address.Address) (migration.Acto
return actor, nil
}

func (fvmSimulator *FvmSimulator) SelfRoot() (cid.Cid, error) {
return fvmSimulator.rootCid, nil
}

func (fvmSimulator *FvmSimulator) SelfSetRoot(id cid.Cid) error {
fvmSimulator.rootCid = id
return nil
}

func (fvmSimulator *FvmSimulator) SelfCurrentBalance() (abi.TokenAmount, error) {
fvmSimulator.actorLk.Lock()
defer fvmSimulator.actorLk.Unlock()

actor, ok := fvmSimulator.actorsMap[fvmSimulator.callContext.Caller]
if !ok {
return abi.TokenAmount{}, ErrorNotFound
}
return actor.Balance, nil
}

func (fvmSimulator *FvmSimulator) SelfDestruct(addr address.Address) error {
fvmSimulator.actorLk.Lock()
defer fvmSimulator.actorLk.Unlock()

actorId, ok := fvmSimulator.addressMap[addr] //nolint
if !ok {
return ErrorNotFound
}
delete(fvmSimulator.actorsMap, actorId)
return nil
}

func (fvmSimulator *FvmSimulator) Create(codec uint64, data []byte) (uint32, error) {
index := fvmSimulator.blockCreate(codec, data)
return index, nil
}

func (fvmSimulator *FvmSimulator) Read(id uint32, offset, size uint32) ([]byte, uint32, error) {
data, err := fvmSimulator.blockRead(id, offset)
if err != nil {
return nil, 0, err
}
if size < uint32(len(data)) {
return data[:size], uint32(len(data)) - size, nil
}
return data, 0, nil
}

func (fvmSimulator *FvmSimulator) Stat(id uint32) (*types.IpldStat, error) {
return fvmSimulator.blockStat(id)
}

func (fvmSimulator *FvmSimulator) BlockLink(id uint32, hashFun uint64, hashLen uint32, cidBuf []byte) (cid.Cid, error) {
return fvmSimulator.blockLink(id, hashFun, hashLen)
}

func (fvmSimulator *FvmSimulator) ResolveBuiltinActorType(codeCid cid.Cid) (types.ActorType, error) {
for k, v := range EmbeddedBuiltinActors {
if v == codeCid {
Expand Down Expand Up @@ -117,16 +56,8 @@ func (fvmSimulator *FvmSimulator) Log(msg string) error {
return nil
}

func (fvmSimulator *FvmSimulator) GetChainRandomness(dst int64, round int64, entropy []byte) (abi.Randomness, error) {
return makeRandomness(dst, round, entropy), nil
}

func (fvmSimulator *FvmSimulator) GetBeaconRandomness(dst int64, round int64, entropy []byte) (abi.Randomness, error) {
return makeRandomness(dst, round, entropy), nil
}

func (fvmSimulator *FvmSimulator) SetCallContext(callcontext *types.InvocationContext) {
fvmSimulator.callContext = callcontext
func (fvmSimulator *FvmSimulator) SetCallContext(callContext *types.InvocationContext) {
fvmSimulator.callContext = callContext
}

func (fvmSimulator *FvmSimulator) VMContext() (*types.InvocationContext, error) {
Expand Down
39 changes: 39 additions & 0 deletions sdk/sys/simulated/sself.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package simulated

import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"
)

func (fvmSimulator *FvmSimulator) SelfRoot() (cid.Cid, error) {
return fvmSimulator.rootCid, nil
}

func (fvmSimulator *FvmSimulator) SelfSetRoot(id cid.Cid) error {
fvmSimulator.rootCid = id
return nil
}

func (fvmSimulator *FvmSimulator) SelfCurrentBalance() (abi.TokenAmount, error) {
fvmSimulator.actorLk.Lock()
defer fvmSimulator.actorLk.Unlock()

actor, ok := fvmSimulator.actorsMap[fvmSimulator.callContext.Caller]
if !ok {
return abi.TokenAmount{}, ErrorNotFound
}
return actor.Balance, nil
}

func (fvmSimulator *FvmSimulator) SelfDestruct(addr address.Address) error {
fvmSimulator.actorLk.Lock()
defer fvmSimulator.actorLk.Unlock()

actorId, ok := fvmSimulator.addressMap[addr] //nolint
if !ok {
return ErrorNotFound
}
delete(fvmSimulator.actorsMap, actorId)
return nil
}
2 changes: 1 addition & 1 deletion tools/sdk_tool/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ fn main() {
let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}
}

0 comments on commit 58b843d

Please sign in to comment.