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

Multicall #72

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ type Client struct {
*rpc.Client
}

// Multicall performs a multicall request.
// `calls` should be constructed with `NewMulticallArg`
// and `outs` must be a slice of pointers.
// If the response contains at least one fault,
// the first is returned as a `MulticallFault` error.
func (c Client) Multicall(calls []MulticallArg, outs ...interface{}) error {
if len(calls) != len(outs) {
return errors.New("lengths of calls and responses are not matching")
}
tmp := multicallOut{calls: calls, datas: outs}
return c.Call("system.multicall", calls, tmp)
}

// clientCodec is rpc.ClientCodec interface implementation.
type clientCodec struct {
// url presents url of xmlrpc service
Expand Down
2 changes: 0 additions & 2 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
// Base64 represents value in base64 encoding
type Base64 string

type encodeFunc func(reflect.Value) ([]byte, error)

func marshal(v interface{}) ([]byte, error) {
if v == nil {
return []byte{}, nil
Expand Down
194 changes: 194 additions & 0 deletions fixtures/multicall_error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
<array>
<data>
<value>
<array>
<data>
<value>
<struct>
<member>
<name>label</name>
<value>
<string>Test</string>
</value>
</member>
<member>
<name>orderby</name>
<value>
<string>date</string>
</value>
</member>
<member>
<name>ordertype</name>
<value>
<string>ascending</string>
</value>
</member>
<member>
<name>date</name>
<value>
<double>1565526014000</double>
</value>
</member>
<member>
<name>createddate</name>
<value>
<double>1565526019000</double>
</value>
</member>
<member>
<name>lastvisitdate</name>
<value>
<double>1565526459000</double>
</value>
</member>
<member>
<name>lastfileaddeddate</name>
<value>
<double>1565526368000</double>
</value>
</member>
<member>
<name>public</name>
<value>
<int>0</int>
</value>
</member>
<member>
<name>allowdownload</name>
<value>
<int>1</int>
</value>
</member>
<member>
<name>allowupload</name>
<value>
<int>0</int>
</value>
</member>
<member>
<name>allowprintorder</name>
<value>
<int>1</int>
</value>
</member>
<member>
<name>allowsendcomments</name>
<value>
<int>1</int>
</value>
</member>
</struct>
</value>
<value>
<struct>
<member>
<name>label</name>
<value>
<string>test2</string>
</value>
</member>
<member>
<name>orderby</name>
<value>
<string>date</string>
</value>
</member>
<member>
<name>ordertype</name>
<value>
<string>ascending</string>
</value>
</member>
<member>
<name>date</name>
<value>
<double>1565526625000</double>
</value>
</member>
<member>
<name>createddate</name>
<value>
<double>1565526629000</double>
</value>
</member>
<member>
<name>lastvisitdate</name>
<value>
<double>1581931485000</double>
</value>
</member>
<member>
<name>lastfileaddeddate</name>
<value>
<double>1565526652000</double>
</value>
</member>
<member>
<name>public</name>
<value>
<int>0</int>
</value>
</member>
<member>
<name>allowdownload</name>
<value>
<int>1</int>
</value>
</member>
<member>
<name>allowupload</name>
<value>
<int>0</int>
</value>
</member>
<member>
<name>allowprintorder</name>
<value>
<int>1</int>
</value>
</member>
<member>
<name>allowsendcomments</name>
<value>
<int>1</int>
</value>
</member>
</struct>
</value>
</data>
</array>
</value>
</data>
</array>
</value>
<value>
<struct>
<member>
<name>faultCode</name>
<value>
<int>205</int>
</value>
</member>
<member>
<name>faultString</name>
<value>
<string>Error (205) : Can&apos;t get properties for the session xxxx
</string>
</value>
</member>
</struct>
</value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>
45 changes: 45 additions & 0 deletions fixtures/multicall_ok.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
<array>
<data>
<value>
<struct>
<member>
<name>nbfiles</name>
<value>
<int>4</int>
</value>
</member>
</struct>
</value>
</data>
</array>
</value>
<value>
<array>
<data>
<value>
<struct>
<member>
<name>nbfiles</name>
<value>
<int>1</int>
</value>
</member>
</struct>
</value>
</data>
</array>
</value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>
2 changes: 1 addition & 1 deletion is_zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func isZero(v Value) bool {
default:
// This should never happens, but will act as a safeguard for
// later, as a default value doesn't makes sense here.
panic(&ValueError{"reflect.Value.IsZero", v.Kind()})
panic(&ValueError{Method: "reflect.Value.IsZero", Kind: v.Kind()})
}
}
Loading