good morning!!!!

Skip to content
Snippets Groups Projects
Commit 8b19d10a authored by Garet Halliday's avatar Garet Halliday
Browse files

upload solidity

parent 321f7426
No related branches found
No related tags found
No related merge requests found
Pipeline #22286 passed
......@@ -48,15 +48,36 @@ func (s *Impl) makeEventSignature(sig *sig.Entry) api.EventSignature {
}
func (s *Impl) APIV1ImportSolidityPost(ctx context.Context, req api.APIV1ImportSolidityPostReq) (*api.UploadResult, error) {
var sourceCode string
switch r := req.(type) {
case *api.APIV1ImportSolidityPostApplicationJSON:
_ = r.SourceCode
sourceCode = r.SourceCode
case *api.APIV1ImportSolidityPostApplicationXWwwFormUrlencoded:
_ = r.SourceCode
sourceCode = r.SourceCode
case *api.ImportSolidityMultipart:
_ = r.SourceCode
sourceCode = r.SourceCode
}
panic("not implemented") // TODO: Implement
entries := sig.FromSolidity(sourceCode)
res := &api.UploadResult{}
for _, entry := range entries {
res.NumProcessed++
addedSig, err := s.Store.Put(ctx, entry)
if err != nil {
return nil, err
}
if addedSig == nil {
res.NumDuplicates++
} else {
res.NumImported++
}
}
return res, nil
}
func (s *Impl) APIV1ImportAbiPost(ctx context.Context, req api.APIV1ImportAbiPostReq) (*api.UploadResult, error) {
......@@ -115,6 +136,15 @@ func (s *Impl) APIV1ImportAbiPost(ctx context.Context, req api.APIV1ImportAbiPos
return nil, err
}
}
if err = handleSig(parsedAbi.Constructor.Sig); err != nil {
return nil, err
}
if err = handleSig(parsedAbi.Fallback.Sig); err != nil {
return nil, err
}
if err = handleSig(parsedAbi.Receive.Sig); err != nil {
return nil, err
}
return res, nil
}
......
package sig
import (
"strings"
"time"
"gfx.cafe/open/4byte/common/util/hashpool"
......@@ -33,6 +34,33 @@ func FromText(s string) *Entry {
return entry
}
func FromSolidity(src string) []*Entry {
var entries []*Entry
for {
idx := strings.Index(src, "function")
if idx == -1 {
break
}
// try to read signature
sig, ok := Normalize(src[idx:])
src = src[idx+len("function"):]
if !ok {
continue
}
entry := &Entry{
Signature: sig,
CreatedAt: time.Now(),
}
entry.init()
entries = append(entries, entry)
}
return entries
}
func (e *Entry) init() {
e.calculateEventHash()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment