Skip to content

Commit

Permalink
Introduce endpoint for issued assets and change the way we return uni…
Browse files Browse the repository at this point in the history
…t of measurement
  • Loading branch information
LINCKODE committed May 23, 2024
1 parent 2f65cd5 commit d905d9f
Show file tree
Hide file tree
Showing 5 changed files with 560 additions and 200 deletions.
63 changes: 60 additions & 3 deletions foundation/rpc_server/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ func (s *Server) Start() error {
}

func int8ArrayToString(array []int8) string {

runes := make([]rune, 0)

for _, char := range array {
Expand All @@ -280,6 +279,64 @@ func int8ArrayToString(array []int8) string {
return string(runes)
}

func int8ArrayToInt32Array(array []int8) []int32 {
ints := make([]int32, 0)

for _, smallInt := range array {
ints = append(ints, int32(smallInt))
}
return ints
}

func (s *Server) GetIssuedAssets(ctx context.Context, req *protobuff.IssuedAssetsRequest) (*protobuff.IssuedAssetsResponse, error) {
client, err := s.qPool.Get()
if err != nil {
return nil, status.Errorf(codes.Internal, "getting pool connection :%v", err)
}

assets, err := client.GetIssuedAssets(ctx, req.Identity)
if err != nil {
s.qPool.Close(client)
return nil, status.Errorf(codes.Internal, "getting issued assets from node %v", err)
}

s.qPool.Put(client)

issuedAssets := make([]*protobuff.IssuedAsset, 0)

for _, asset := range assets {

iAsset := asset.Data
var iAssetIdentity types.Identity
iAssetIdentity, err = iAssetIdentity.FromPubKey(iAsset.PublicKey, false)
if err != nil {
return nil, errors.Wrap(err, "failed to get identity for issued asset public key")
}

data := protobuff.IssuedAssetData{
IssuerIdentity: iAssetIdentity.String(),
Type: uint32(iAsset.Type),
Name: int8ArrayToString(iAsset.Name[:]),
NumberOfDecimalPlaces: int32(iAsset.NumberOfDecimalPlaces),
UnitOfMeasurement: int8ArrayToInt32Array(iAsset.UnitOfMeasurement[:]),
}

info := protobuff.AssetInfo{
Tick: asset.Info.Tick,
UniverseIndex: asset.Info.UniverseIndex,
}

issuedAsset := protobuff.IssuedAsset{
Data: &data,
Info: &info,
}

issuedAssets = append(issuedAssets, &issuedAsset)
}

return &protobuff.IssuedAssetsResponse{IssuedAssets: issuedAssets}, nil
}

func (s *Server) GetOwnedAssets(ctx context.Context, req *protobuff.OwnedAssetsRequest) (*protobuff.OwnedAssetsResponse, error) {
client, err := s.qPool.Get()
if err != nil {
Expand Down Expand Up @@ -311,7 +368,7 @@ func (s *Server) GetOwnedAssets(ctx context.Context, req *protobuff.OwnedAssetsR
Type: uint32(iAsset.Type),
Name: int8ArrayToString(iAsset.Name[:]),
NumberOfDecimalPlaces: int32(iAsset.NumberOfDecimalPlaces),
UnitOfMeasurement: int8ArrayToString(iAsset.UnitOfMeasurement[:]),
UnitOfMeasurement: int8ArrayToInt32Array(iAsset.UnitOfMeasurement[:]),
}

var oAssetIdentity types.Identity
Expand Down Expand Up @@ -384,7 +441,7 @@ func (s *Server) GetPossessedAssets(ctx context.Context, req *protobuff.Possesse
Type: uint32(iAsset.Type),
Name: int8ArrayToString(iAsset.Name[:]),
NumberOfDecimalPlaces: int32(iAsset.NumberOfDecimalPlaces),
UnitOfMeasurement: int8ArrayToString(iAsset.UnitOfMeasurement[:]),
UnitOfMeasurement: int8ArrayToInt32Array(iAsset.UnitOfMeasurement[:]),
}

ownedAsset := protobuff.OwnedAssetData{
Expand Down
Loading

0 comments on commit d905d9f

Please sign in to comment.