Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce advanced Web3.go capabilities (Devel Branch)... #140

Closed
wants to merge 80 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
aa9d4fd
Account management support
0x19 Nov 14, 2023
b28422a
Merge branch 'main' into accounts
0x19 Nov 14, 2023
3852f75
Storage and bindings generation improvements
0x19 Nov 15, 2023
37b451f
Bunch of new additions
0x19 Nov 22, 2023
a118d2f
Improvements on logs, and overall observer data accessibilitiy
0x19 Nov 22, 2023
aa4ecbd
Yet more boilderplates, playground code, nowhere yete...
0x19 Nov 25, 2023
012e96d
Yet another round of shit code...
0x19 Nov 25, 2023
767e717
A bit more order into chaos
0x19 Nov 25, 2023
ff117a2
More improvements to the inspector :rocket:
0x19 Nov 26, 2023
9669091
Foobar storage, not working at all yet
0x19 Nov 26, 2023
9578320
Yet another round of insanity...
0x19 Nov 26, 2023
bd5f04f
Inspector transfer updates
0x19 Nov 26, 2023
7c107f6
Visitor improvements and basic _transfer detection
0x19 Nov 26, 2023
ebd8f3b
More inspector improvements
0x19 Nov 26, 2023
4a54ef5
Cleanups
0x19 Nov 26, 2023
c7f4424
Improvement of ownership
0x19 Nov 26, 2023
3f02874
Partially working storage retrieval
0x19 Nov 27, 2023
19197b1
Fixing slot declaration id discovery and sorting
0x19 Nov 27, 2023
f0f2b05
Storage layout reader works better now, when it works... Some strange…
0x19 Nov 27, 2023
aef46a5
Some fixes.... String, Struct, Mapping still needs to be sorted out
0x19 Nov 27, 2023
bceb794
So far it looks like ordering of the slots is resolved... Getting clo…
0x19 Nov 27, 2023
e0e098a
Additional cleanups and simulated backend implementation
0x19 Nov 27, 2023
6c3b457
Docs and more docs
0x19 Nov 27, 2023
85ebb98
Well... Anvil simulator with ability to impersonate accounts
0x19 Dec 2, 2023
a637d93
Improving simulator statuses and speeding up faucet setup
0x19 Dec 2, 2023
a1d0d6f
Ability to spawn new avail node for particular block on the fly...
0x19 Dec 2, 2023
44db494
Thanks OpenAI on the nice docs...
0x19 Dec 2, 2023
91d3d9c
Impersonating account tests... Oh god...
0x19 Dec 2, 2023
fc3be57
Basic simulator/node docs
0x19 Dec 2, 2023
ff2d928
Just basic path to web3 package...
0x19 Dec 2, 2023
0e7d651
Removal of dummy files...
0x19 Dec 2, 2023
6968b0c
Note about anvil custom method future integrations
0x19 Dec 2, 2023
2857ca0
Note about anvil custom method future integrations
0x19 Dec 2, 2023
514c7cb
Helper for testing with simulator throughout solgo packages
0x19 Dec 2, 2023
d899244
Fixing storage tests
0x19 Dec 2, 2023
94206ae
Fixing storage tests
0x19 Dec 2, 2023
fdae69a
Resolving all direct errors
0x19 Dec 2, 2023
c9a6872
Inspector now accepts simulator
0x19 Dec 2, 2023
8ed7287
Basic accounts test and removal of functionality that is not needed...
0x19 Dec 2, 2023
4ed5da7
Accounts package is ready i guess...
0x19 Dec 2, 2023
abe6a6e
Merging master to devel branch
0x19 Dec 2, 2023
192a014
Changes to the inspector, mostly docs
0x19 Dec 2, 2023
675fc9b
Inspector / Detector interface improvements
0x19 Dec 2, 2023
cda3336
Adding token (ERC-20) detector type
0x19 Dec 2, 2023
76227c3
Adding standards detector
0x19 Dec 2, 2023
67b173a
....
0x19 Dec 2, 2023
8a0ad3d
Approval almost there...
0x19 Dec 2, 2023
33015c3
Screwing up with approvals, something is not right...
0x19 Dec 3, 2023
7932e34
Renaming anvil_impersonate to anvil_methods
0x19 Dec 3, 2023
2ecb654
Simulator can be started without a single node...
0x19 Dec 3, 2023
50b4e2d
Making sure we error log revert messages from anvil node
0x19 Dec 3, 2023
02dea69
Approve works...
0x19 Dec 3, 2023
4799418
Transfer almost working...
0x19 Dec 3, 2023
d33c45c
Changing direction buying directly from exchange... Not yet fully wor…
0x19 Dec 3, 2023
72d823d
Buy and sell now works but it's fucking ugly...
0x19 Dec 3, 2023
b1f2b34
This is just way too complicated, lets unclusterfuck ourselves with g…
0x19 Dec 3, 2023
661d16a
A little bit of changes
0x19 Dec 9, 2023
3de2fff
A bit cleanup + fix for DecodeTransaction
0x19 Dec 9, 2023
42b447c
Adding storage and simulator extension to new contract
0x19 Dec 9, 2023
49bb9d5
Dropping observers package from this particular PR
0x19 Dec 9, 2023
067296a
Inspector updates + resolution of most of abi issues
0x19 Dec 11, 2023
cad36df
Sorting out abi issues in unit tests
0x19 Dec 11, 2023
11bd543
Determionistic sort and foobar stuff
0x19 Dec 11, 2023
73cbb0d
Topological deterministic sort
0x19 Dec 12, 2023
8b1fe0b
Unit test fixes
0x19 Dec 12, 2023
a7c39f2
Import path source unit resolution fixes
0x19 Dec 12, 2023
301849a
CFG, Storage Fix, AST/IR Improvements
0x19 Dec 12, 2023
92c405a
Bughunt...
0x19 Dec 12, 2023
b1ab8d5
Not yet sure how to do it so ommiting and will fix it later (string d…
0x19 Dec 14, 2023
ce03b65
Resolving payable conversion ast type_name reference not found
0x19 Dec 14, 2023
951d78e
Changes to the tests, adding almost completed event signature ir.even…
0x19 Dec 16, 2023
6a3be6b
Aiii... A lot of crap that's still not working
0x19 Dec 17, 2023
c04449d
Different fixes...
0x19 Dec 22, 2023
1d2b66a
Resolving parameter discovery in AST, introducing address to ABI buil…
0x19 Dec 23, 2023
676132d
Upgrading crypto to 0.17
0x19 Dec 23, 2023
c2643a6
...
0x19 Dec 25, 2023
5254c5e
Memory optimisation, contract downloading optimisation and fast fix f…
0x19 Dec 29, 2023
7e4c100
Better path handling for sources, fixing major bug where source code …
0x19 Dec 31, 2023
4683e14
More updates
0x19 Mar 6, 2024
0017720
More updates...
0x19 Mar 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ jobs:
SOLC_SWITCH_GITHUB_TOKEN: ${{ secrets.SOLC_SWITCH_GITHUB_TOKEN }}
FULL_NODE_TEST_URL: ${{ secrets.FULL_NODE_TEST_URL }}
ARCHIVE_NODE_TEST_URL: ${{ secrets.ARCHIVE_NODE_TEST_URL }}
# Initialize SOLGO_ANVIL_PATH, will be set after installing Foundry
SOLGO_ANVIL_PATH: ''
steps:
- name: Checkout Source
uses: actions/checkout@v3

# Install Foundry and Anvil
- name: Install Foundry and Anvil
run: |
curl -L https://foundry.paradigm.xyz | bash
foundryup
echo "SOLGO_ANVIL_PATH=$(which anvil)" >> $GITHUB_ENV

# Install solc-select
- name: Install solc-select
run: |
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/goveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
SOLC_SWITCH_GITHUB_TOKEN: ${{ secrets.SOLC_SWITCH_GITHUB_TOKEN }}
FULL_NODE_TEST_URL: ${{ secrets.FULL_NODE_TEST_URL }}
ARCHIVE_NODE_TEST_URL: ${{ secrets.ARCHIVE_NODE_TEST_URL }}
# Initialize SOLGO_ANVIL_PATH, will be set after installing Foundry
SOLGO_ANVIL_PATH: ''
strategy:
fail-fast: false
matrix:
Expand All @@ -20,6 +22,13 @@ jobs:
- uses: actions/checkout@v3
- run: make submodules

# Install Foundry and Anvil
- name: Install Foundry and Anvil
run: |
curl -L https://foundry.paradigm.xyz | bash
foundryup
echo "SOLGO_ANVIL_PATH=$(which anvil)" >> $GITHUB_ENV

# Install solc-select
- name: Install solc-select
run: |
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
SOLC_SWITCH_GITHUB_TOKEN: ${{ secrets.SOLC_SWITCH_GITHUB_TOKEN }}
FULL_NODE_TEST_URL: ${{ secrets.FULL_NODE_TEST_URL }}
ARCHIVE_NODE_TEST_URL: ${{ secrets.ARCHIVE_NODE_TEST_URL }}
SOLGO_ANVIL_PATH: ''
steps:
- name: Checkout Source
uses: actions/checkout@v3
Expand All @@ -19,6 +20,12 @@ jobs:
- name: Checkout submodules
run: make submodules

- name: Install Foundry and Anvil
run: |
curl -L https://foundry.paradigm.xyz | bash
foundryup
echo "SOLGO_ANVIL_PATH=$(which anvil)" >> $GITHUB_ENV

- name: Install solc-select
run: |
python3 -m venv solgoenv
Expand All @@ -35,6 +42,4 @@ jobs:
- name: Run Tests
run: |
source solgoenv/bin/activate
solc-select install 0.8.19
solc-select use 0.8.19
make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ go.work
solgo
playground/*
bin/*
exchanges_old/*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Once I am confident that the project is fully ready for production, this disclai

The SolGo basic documentation is hosted on GitHub, ensuring it's always up-to-date with the latest changes and features. You can access the full documentation [here](https://github.com/unpackdev/solgo/wiki).

**NOTE: Statement above is not true yet (lazy to change it)... Documentation is still being written.**

## Getting Started

Detailed examples of how to install and use this package can be found in the [Usage](https://github.com/unpackdev/solgo/wiki/Getting-Started) section.
Expand Down
9 changes: 6 additions & 3 deletions abi/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func NewBuilderFromSources(ctx context.Context, sources *solgo.Sources) (*Builde
parser: parser,
astBuilder: parser.GetAstBuilder(),
resolver: &TypeResolver{
parser: parser,
parser: parser,
processedTypes: make(map[string]bool),
},
}, nil
}
Expand Down Expand Up @@ -124,9 +125,11 @@ func (b *Builder) Parse() (errs []error) {
}

// Build constructs the ABIs from the sources.
func (b *Builder) Build() error {
func (b *Builder) Build() (err error) {
if root := b.GetParser().GetRoot(); root != nil {
b.root = b.processRoot(root)
if b.root, err = b.processRoot(root); err != nil {
return err
}
}
return nil
}
26 changes: 11 additions & 15 deletions abi/constructor.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package abi

import "github.com/unpackdev/solgo/ir"
import (
"fmt"

"github.com/unpackdev/solgo/ir"
)

// processConstructor processes an IR constructor and returns a Method representation of it.
// It extracts the input and output parameters of the constructor and normalizes its state mutability.
func (b *Builder) processConstructor(unit *ir.Constructor) *Method {
func (b *Builder) processConstructor(unit *ir.Constructor) (*Method, error) {
// Initialize a new Method structure for the constructor.
toReturn := &Method{
Name: "", // Constructors in Ethereum don't have a name.
Expand All @@ -15,6 +19,10 @@ func (b *Builder) processConstructor(unit *ir.Constructor) *Method {
}

for _, parameter := range unit.GetParameters() {
if parameter.GetTypeDescription() == nil {
return nil, fmt.Errorf("nil type description for constructor parameter %s", parameter.GetName())
}

methodIo := MethodIO{
Name: parameter.GetName(),
}
Expand All @@ -24,17 +32,5 @@ func (b *Builder) processConstructor(unit *ir.Constructor) *Method {
)
}

// Process return statements of the constructor.
// Note: In Ethereum, constructors don't return values. This might be specific to the IR representation.
/* for _, parameter := range unit.GetReturnStatements() {
methodIo := MethodIO{
Name: parameter.GetName(),
}
toReturn.Outputs = append(
toReturn.Outputs,
b.buildMethodIO(methodIo, parameter.GetTypeDescription()),
)
} */

return toReturn
return toReturn, nil
}
3 changes: 2 additions & 1 deletion abi/constructor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func TestProcessConstructor(t *testing.T) {
}

builder := &Builder{}
result := builder.processConstructor(mockConstructor)
result, err := builder.processConstructor(mockConstructor)
assert.NoError(t, err)

// Assert that the returned Method object has the expected properties
assert.Equal(t, "constructor", result.Type)
Expand Down
48 changes: 34 additions & 14 deletions abi/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package abi

import (
abi_pb "github.com/unpackdev/protos/dist/go/abi"
ast_pb "github.com/unpackdev/protos/dist/go/ast"
"github.com/unpackdev/solgo/ast"
"github.com/unpackdev/solgo/ir"
)
Expand Down Expand Up @@ -44,39 +45,56 @@ func (c *Contract) ToProto() *abi_pb.Contract {

// processContract processes an IR contract and returns a Contract representation of it.
// It extracts state variables, events, errors, constructor, functions, fallback, and receive methods.
func (b *Builder) processContract(contract *ir.Contract) *Contract {
func (b *Builder) processContract(contract *ir.Contract) (*Contract, error) {
toReturn := Contract{}

// Process state variables.
for _, stateVar := range contract.GetStateVariables() {
//fmt.Println("StateVar:", stateVar.GetName())
method := b.processStateVariable(stateVar)
toReturn = append(toReturn, method)
}

// Process events.
for _, event := range contract.GetEvents() {
method := b.processEvent(event)
method, err := b.processEvent(event)
if err != nil {
return nil, err
}

toReturn = append(toReturn, method)
}

// Process errors.
for _, errorNode := range contract.GetErrors() {
method := b.processError(errorNode)
method, err := b.processError(errorNode)
if err != nil {
return nil, err
}

toReturn = append(toReturn, method)
}

// Process constructor.
if contract.GetConstructor() != nil {
toReturn = append(
toReturn,
b.processConstructor(contract.GetConstructor()),
)
method, err := b.processConstructor(contract.GetConstructor())
if err != nil {
return nil, err
}

toReturn = append(toReturn, method)
}

// Process functions.
for _, function := range contract.GetFunctions() {
method := b.processFunction(function)
toReturn = append(toReturn, method)
if function.GetVisibility() == ast_pb.Visibility_PUBLIC && function.GetVisibility() == ast_pb.Visibility_EXTERNAL {
method, err := b.processFunction(function)
if err != nil {
return nil, err
}

toReturn = append(toReturn, method)
}
}

// Process fallback.
Expand All @@ -89,13 +107,15 @@ func (b *Builder) processContract(contract *ir.Contract) *Contract {

// Process receive.
if contract.GetReceive() != nil {
toReturn = append(
toReturn,
b.processReceive(contract.GetReceive()),
)
method, err := b.processReceive(contract.GetReceive())
if err != nil {
return nil, err
}

toReturn = append(toReturn, method)
}

return &toReturn
return &toReturn, nil
}

// buildMethodIO constructs a MethodIO object based on the provided method and type description.
Expand Down
27 changes: 19 additions & 8 deletions abi/error.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package abi

import (
"fmt"

"github.com/unpackdev/solgo/ir"
"github.com/unpackdev/solgo/utils"
)

// processError processes an IR error and returns a Method representation of it.
// It extracts the name and parameters of the error and sets its type to "error" and state mutability to "view".
func (b *Builder) processError(unit *ir.Error) *Method {
func (b *Builder) processError(unit *ir.Error) (*Method, error) {
toReturn := &Method{
Name: unit.GetName(),
Inputs: make([]MethodIO, 0),
Expand All @@ -16,13 +19,21 @@ func (b *Builder) processError(unit *ir.Error) *Method {
}

for _, parameter := range unit.GetParameters() {
toReturn.Inputs = append(toReturn.Inputs, MethodIO{
Name: parameter.GetName(),
Type: normalizeTypeName(parameter.GetTypeDescription().GetString()),
InternalType: parameter.GetTypeDescription().GetString(),
Indexed: true, // Parameters for errors are indexed by default.
})
if parameter.GetTypeDescription() == nil {
fmt.Println("PROCESS ERROR ABI")
utils.DumpNodeNoExit(parameter)
return nil, fmt.Errorf("nil type description for error parameter %s", parameter.GetName())
}

methodIo := MethodIO{
Name: parameter.GetName(),
Indexed: parameter.IsIndexed(),
}
toReturn.Inputs = append(
toReturn.Inputs,
b.buildMethodIO(methodIo, parameter.GetTypeDescription()),
)
}

return toReturn
return toReturn, nil
}
7 changes: 5 additions & 2 deletions abi/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestProcessError(t *testing.T) {
Name: "param1",
Type: "uint256",
InternalType: "uint256",
Indexed: true,
Indexed: false,
},
},
Outputs: []MethodIO{},
Expand All @@ -52,12 +52,14 @@ func TestProcessError(t *testing.T) {
TypeDescription: &ast.TypeDescription{
TypeString: "uint256",
},
Indexed: true,
},
{
Name: "param2",
TypeDescription: &ast.TypeDescription{
TypeString: "address",
},
Indexed: true,
},
},
},
Expand Down Expand Up @@ -88,7 +90,8 @@ func TestProcessError(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := builder.processError(tt.input)
result, err := builder.processError(tt.input)
assert.NoError(t, err)
assert.Equal(t, tt.expected, result)
})
}
Expand Down
33 changes: 25 additions & 8 deletions abi/event.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package abi

import (
"fmt"

"github.com/unpackdev/solgo/ir"
)

// processEvent processes an IR event and returns a Method representation of it.
// It extracts the name and parameters of the event and sets its type to "event" and state mutability to "view".
func (b *Builder) processEvent(unit *ir.Event) *Method {
func (b *Builder) processEvent(unit *ir.Event) (*Method, error) {
toReturn := &Method{
Name: unit.GetName(),
Inputs: make([]MethodIO, 0),
Expand All @@ -18,13 +20,28 @@ func (b *Builder) processEvent(unit *ir.Event) *Method {
// Process parameters of the event.
// Note: In Ethereum, event parameters are considered as outputs.
for _, parameter := range unit.GetParameters() {
toReturn.Outputs = append(toReturn.Outputs, MethodIO{
Name: parameter.GetName(),
Type: parameter.GetTypeDescription().TypeString,
InternalType: parameter.GetTypeDescription().TypeString,
Indexed: true, // Parameters for events can be indexed.
})
if parameter.GetTypeDescription() == nil {
return nil, fmt.Errorf("nil type description for event parameter %s", parameter.GetName())
}

methodIo := MethodIO{
Name: parameter.GetName(),
Indexed: parameter.IsIndexed(),
}
toReturn.Inputs = append(
toReturn.Inputs,
b.buildMethodIO(methodIo, parameter.GetTypeDescription()),
)
}

return toReturn, nil
}

func (b *Builder) GetEventAsAbi(unit *ir.Event) ([]*Method, error) {
method, err := b.processEvent(unit)
if err != nil {
return nil, err
}

return toReturn
return []*Method{method}, nil
}
Loading
Loading