-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-network-defaults
- Loading branch information
Showing
9 changed files
with
321 additions
and
7 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
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,57 @@ | ||
package aptos | ||
|
||
type MoveResource struct { | ||
Tag MoveStructTag | ||
Value map[string]any // MoveStructValue // TODO: api/types/src/move_types.rs probably actually has more to say about what a MoveStructValue is, but at first read it effectively says map[string]any; there's probably convention elesewhere about what goes into those 'any' parts | ||
} | ||
|
||
func (mr *MoveResource) MarshalBCS(bcs *Serializer) { | ||
panic("TODO") | ||
} | ||
func (mr *MoveResource) UnmarshalBCS(bcs *Deserializer) { | ||
mr.Tag.UnmarshalBCS(bcs) | ||
} | ||
|
||
type MoveStructTag struct { | ||
Address AccountAddress | ||
Module string // TODO: IdentifierWrapper ? | ||
Name string // TODO: IdentifierWrapper ? | ||
GenericTypeParams []MoveType | ||
} | ||
|
||
func (mst *MoveStructTag) MarshalBCS(bcs *Serializer) { | ||
panic("TODO") | ||
} | ||
func (mst *MoveStructTag) UnmarshalBCS(bcs *Deserializer) { | ||
mst.Address.UnmarshalBCS(bcs) | ||
mst.Module = bcs.ReadString() | ||
mst.Name = bcs.ReadString() | ||
mst.GenericTypeParams = DeserializeSequence[MoveType](bcs) | ||
} | ||
|
||
// enum | ||
type MoveType uint8 | ||
|
||
const ( | ||
MoveType_Bool MoveType = 0 | ||
MoveType_U8 MoveType = 1 | ||
MoveType_U16 MoveType = 2 | ||
MoveType_U32 MoveType = 3 | ||
MoveType_U64 MoveType = 4 | ||
MoveType_U128 MoveType = 5 | ||
MoveType_U256 MoveType = 6 | ||
MoveType_Address MoveType = 7 | ||
MoveType_Signer MoveType = 8 | ||
MoveType_Vector MoveType = 9 // contains MoveType of items of vector | ||
MoveType_MoveStructTag MoveType = 10 // contains a MoveStructTag | ||
MoveType_GeneritTypeParam MoveType = 11 // contains a uint16 | ||
MoveType_Reference MoveType = 12 // {mutable bool, to MoveType} | ||
MoveType_Unparsable MoveType = 13 // contains a string | ||
) | ||
|
||
func (mt *MoveType) MarshalBCS(bcs *Serializer) { | ||
bcs.Uleb128(uint64(*mt)) | ||
} | ||
func (mt *MoveType) UnmarshalBCS(bcs *Deserializer) { | ||
*mt = MoveType(bcs.Uleb128()) | ||
} |
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,36 @@ | ||
package aptos | ||
|
||
import ( | ||
"encoding/base64" | ||
"io" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func decodeB64(x string) ([]byte, error) { | ||
reader := strings.NewReader(x) | ||
dec := base64.NewDecoder(base64.StdEncoding, reader) | ||
return io.ReadAll(dec) | ||
} | ||
|
||
func TestMoveResourceBCS(t *testing.T) { | ||
// fetched from local aptos-node 20240501_152556 | ||
// curl -o /tmp/ar_bcs --header "Accept: application/x-bcs" http://127.0.0.1:8080/v1/accounts/{addr}/resources | ||
// base64 < /tmp/ar_bcs | ||
b64text := "AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBGNvaW4JQ29pblN0b3JlAQcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQphcHRvc19jb2luCUFwdG9zQ29pbgBpKsLrCwAAAAAAAgAAAAAAAAACAAAAAAAAANGdA6RyqwjAFP2cXRokfP3YJqHHNb55lM2GQFYwd6a7AAAAAAAAAAADAAAAAAAAANGdA6RyqwjAFP2cXRokfP3YJqHHNb55lM2GQFYwd6a7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEHYWNjb3VudAdBY2NvdW50AJMBINGdA6RyqwjAFP2cXRokfP3YJqHHNb55lM2GQFYwd6a7AAAAAAAAAAAEAAAAAAAAAAEAAAAAAAAAAAAAAAAAAADRnQOkcqsIwBT9nF0aJHz92CahxzW+eZTNhkBWMHemuwAAAAAAAAAAAQAAAAAAAADRnQOkcqsIwBT9nF0aJHz92CahxzW+eZTNhkBWMHemuwAA" | ||
blob, err := decodeB64(b64text) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, blob) | ||
|
||
bcs := NewDeserializer(blob) | ||
//resources := DeserializeSequence[MoveResource](bcs) | ||
//resourceKeys, resourceValues := DeserializeMap[StructTag, []byte](bcs) | ||
// like client.go AccountResourcesBCS | ||
resources := DeserializeSequence[AccountResourceRecord](bcs) | ||
assert.NoError(t, bcs.Error()) | ||
assert.Equal(t, 2, len(resources)) | ||
assert.Equal(t, "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>", resources[0].Tag.String()) | ||
assert.Equal(t, "0x1::account::Account", resources[1].Tag.String()) | ||
} |
Oops, something went wrong.