Skip to content

Commit

Permalink
Merge pull request #108 from FISCO-BCOS/develop
Browse files Browse the repository at this point in the history
Add mobile ios implementation
  • Loading branch information
bxq2011hust authored Mar 24, 2021
2 parents 6b23fff + 3539e11 commit 5ca92a0
Show file tree
Hide file tree
Showing 15 changed files with 677 additions and 381 deletions.
35 changes: 27 additions & 8 deletions .ci/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

set -e

start_time=5
start_time=10
macOS=
check_amop=
GOPATH_BIN=$(go env GOPATH)/bin
SHELL_FOLDER=$(
cd $(dirname $0)
Expand Down Expand Up @@ -202,8 +203,9 @@ integration_std()
execute_cmd "go build -o counter counter.go"
if [ -z "$(./counter | grep address)" ];then LOG_ERROR "std deploy contract failed." && exit 1;fi
if [ ! -z "$(./counter | grep failed)" ];then LOG_ERROR "call counter failed." && exit 1;fi

integration_amop
if [[ "${check_amop}" == "true" ]];then
integration_amop
fi
bash nodes/127.0.0.1/stop_all.sh
LOG_INFO "integration_std testing pass."

Expand Down Expand Up @@ -250,9 +252,26 @@ integration_amop() {
./subscriber 127.0.0.1:20201 hello1
}

check_env
compile_and_ut
get_build_chain
integration_std
parse_params()
{
echo "parse_params $#"
while getopts "a" option;do
case $option in
a) check_amop="true";;
*) LOG_WARN "invalid option $option";;
esac
done
}

main()
{
check_env
compile_and_ut
get_build_chain
integration_std

if [ -z "${macOS}" ];then integration_gm ; fi
}

if [ -z "${macOS}" ];then integration_gm ; fi
parse_params "$@"
main
6 changes: 5 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ jobs:
- name: check commit
if: ${{ runner.os == 'Linux' && github.base_ref != 'master' && github.event_name == 'pull_request' }}
run: bash .ci/check-commit.sh
- name: test
- name: test all
if: ${{ runner.os == 'Linux' }}
run: bash .ci/integration_test.sh -a
- name: test without amop
if: ${{ runner.os == 'macOS' }}
run: bash .ci/integration_test.sh
10 changes: 5 additions & 5 deletions abi/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,16 @@ func bindBasicTypeObjC(kind abi.Type) string {
switch parts[2] {
case "8", "16", "32":
return "int"
case "64":
case "40", "48", "56", "64":
return "double"
}
return "NSString *"
case abi.UintTy:
parts := regexp.MustCompile(`(u)?int([0-9]*)`).FindStringSubmatch(kind.String())
switch parts[2] {
case "8", "16", "32":
return "unsigned int"
case "64":
return "int"
case "40", "48", "56", "64":
return "double"
}
return "NSString *"
Expand Down Expand Up @@ -391,7 +391,7 @@ func objcFormattedValue(kind abi.Type, valueName string, structs map[string]*tmp
case "8", "16", "32":
//return "[NSString stringWithFormat:@\"%d\", " + valueName + "]"
return "@(" + valueName + ")"
case "64":
case "40", "48", "56", "64":
//return "[NSString stringWithFormat:@\"%.0lf\", " + valueName + "]"
return "@(" + valueName + ")"
}
Expand All @@ -402,7 +402,7 @@ func objcFormattedValue(kind abi.Type, valueName string, structs map[string]*tmp
case "8", "16", "32":
//return "[NSString stringWithFormat:@\"%u\", " + valueName + "]"
return "@(" + valueName + ")"
case "64":
case "40", "48", "56", "64":
//return "[NSString stringWithFormat:@\"%.0lf\", " + valueName + "]"
return "@(" + valueName + ")"
}
Expand Down
11 changes: 3 additions & 8 deletions conn/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ type handshakeRequest struct {
ClientType string `json:"clientType"`
}

type handshakeResponse struct {
Protocol int32 `json:"protocol"`
NodeVersion string `json:"nodeVersion"`
}

type channelResponse struct {
Message *channelMessage
Err error
Expand Down Expand Up @@ -247,7 +242,7 @@ func decodeChannelMessage(raw []byte) (*channelMessage, error) {
fmt.Println("binary.Read failed:", err)
}
dataLength := result.length - messageHeaderLength
result.body = make([]byte, dataLength, dataLength)
result.body = make([]byte, dataLength)
err = binary.Read(buf, binary.BigEndian, &result.body)
if err != nil {
fmt.Println("binary.Read failed:", err)
Expand All @@ -262,14 +257,14 @@ func decodeTopic(raw []byte) (*topicData, error) {
if err != nil {
fmt.Println("binary.Read failed:", err)
}
topic := make([]byte, result.length-1, result.length-1)
topic := make([]byte, result.length-1)
err = binary.Read(buf, binary.LittleEndian, &topic)
if err != nil {
fmt.Println("binary.Read failed:", err)
}
result.topic = string(topic)
dataLength := len(raw) - int(result.length)
result.data = make([]byte, dataLength, dataLength)
result.data = make([]byte, dataLength)
err = binary.Read(buf, binary.LittleEndian, &result.data)
if err != nil {
fmt.Println("binary.Read failed:", err)
Expand Down
6 changes: 5 additions & 1 deletion conn/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"errors"
"io/ioutil"
"log"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -692,7 +693,10 @@ func (c *Connection) read(codec ServerCodec) {
for {
msgs, batch, err := codec.Read()
if _, ok := err.(*json.SyntaxError); ok {
codec.Write(context.Background(), errorMessage(&parseError{err.Error()}))
err := codec.Write(context.Background(), errorMessage(&parseError{err.Error()}))
if err != nil {
log.Fatal(err)
}
}
if err != nil {
c.readErr <- err
Expand Down
26 changes: 21 additions & 5 deletions conn/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package conn
import (
"context"
"encoding/json"
"log"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -90,7 +91,10 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
// Emit error response for empty batches:
if len(msgs) == 0 {
h.startCallProc(func(cp *callProc) {
h.conn.Write(cp.ctx, errorMessage(&invalidRequestError{"empty batch"}))
err := h.conn.Write(cp.ctx, errorMessage(&invalidRequestError{"empty batch"}))
if err != nil {
log.Fatal(err)
}
})
return
}
Expand All @@ -115,10 +119,16 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
}
h.addSubscriptions(cp.notifiers)
if len(answers) > 0 {
h.conn.Write(cp.ctx, answers)
err := h.conn.Write(cp.ctx, answers)
if err != nil {
log.Fatal(err)
}
}
for _, n := range cp.notifiers {
n.activate()
err := n.activate()
if err != nil {
log.Fatal(err)
}
}
})
}
Expand All @@ -132,10 +142,16 @@ func (h *handler) handleMsg(msg *jsonrpcMessage) {
answer := h.handleCallMsg(cp, msg)
h.addSubscriptions(cp.notifiers)
if answer != nil {
h.conn.Write(cp.ctx, answer)
err := h.conn.Write(cp.ctx, answer)
if err != nil {
log.Fatal(err)
}
}
for _, n := range cp.notifiers {
n.activate()
err := n.activate()
if err != nil {
log.Fatal(err)
}
}
})
}
Expand Down
26 changes: 21 additions & 5 deletions conn/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"io"
"log"
"reflect"
"strings"
"sync"
Expand Down Expand Up @@ -215,15 +216,21 @@ func (c *jsonCodec) Write(ctx context.Context, v interface{}) error {
if !ok {
deadline = time.Now().Add(defaultWriteTimeout)
}
c.conn.SetWriteDeadline(deadline)
err := c.conn.SetWriteDeadline(deadline)
if err != nil {
log.Print(err)
}
return c.encode(v)
}

// Close the underlying connection
func (c *jsonCodec) Close() {
c.closer.Do(func() {
close(c.closed)
c.conn.Close()
err := c.conn.Close()
if err != nil {
log.Fatal(err)
}
})
}

Expand All @@ -239,15 +246,24 @@ func (c *jsonCodec) Closed() <-chan interface{} {
func parseMessage(raw json.RawMessage) ([]*jsonrpcMessage, bool) {
if !isBatch(raw) {
msgs := []*jsonrpcMessage{{}}
json.Unmarshal(raw, &msgs[0])
err := json.Unmarshal(raw, &msgs[0])
if err != nil {
log.Fatal(err)
}
return msgs, false
}
dec := json.NewDecoder(bytes.NewReader(raw))
dec.Token() // skip '['
_, err := dec.Token() // skip '['
if err != nil {
log.Fatal(err)
}
var msgs []*jsonrpcMessage
for dec.More() {
msgs = append(msgs, new(jsonrpcMessage))
dec.Decode(&msgs[len(msgs)-1])
err := dec.Decode(&msgs[len(msgs)-1])
if err != nil {
log.Fatal(err)
}
}
return msgs, true
}
Expand Down
11 changes: 9 additions & 2 deletions conn/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"log"
"math/rand"
"reflect"
"strings"
Expand Down Expand Up @@ -63,7 +64,10 @@ func randomIDGenerator() func() ID {
mu.Lock()
defer mu.Unlock()
id := make([]byte, 16)
rng.Read(id)
_, err = rng.Read(id)
if err != nil {
log.Fatal(err)
}
return encodeID(id)
}
}
Expand Down Expand Up @@ -252,7 +256,10 @@ func (sub *ClientSubscription) quitWithError(err error, unsubscribeServer bool)
// unblocks deliver.
close(sub.quit)
if unsubscribeServer {
sub.requestUnsubscribe()
err := sub.requestUnsubscribe()
if err != nil {
log.Fatal(err)
}
}
if err != nil {
if err == ErrClientQuit {
Expand Down
14 changes: 11 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ go 1.13

require (
github.com/FISCO-BCOS/crypto v0.0.0-20200202032121-bd8ab0b5d4f1
github.com/ethereum/go-ethereum v1.9.10
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/aristanetworks/goarista v0.0.0-20210107181124-fad53805024e // indirect
github.com/btcsuite/btcd v0.21.0-beta // indirect
github.com/ethereum/go-ethereum v1.9.16
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
github.com/google/uuid v1.1.1
github.com/holiman/uint256 v1.1.1 // indirect
github.com/shirou/gopsutil v3.20.12+incompatible // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.6.2
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f // indirect
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
gopkg.in/urfave/cli.v1 v1.20.0
)
Loading

0 comments on commit 5ca92a0

Please sign in to comment.