-
Notifications
You must be signed in to change notification settings - Fork 4
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
7 changed files
with
93 additions
and
77 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
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) | ||
} |
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,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 | ||
} |
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,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 | ||
} |
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