Git Product home page Git Product logo

codechain-sdk-go's People

Contributors

baumstern avatar majecty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

codechain-sdk-go's Issues

Update README

Usages are expired.
Since #7 was resolved by #11, the usages are almost fixed.

Handle RPC Error properly

Currently, if RPC error occurs, the error message just gives
unexpected end of JSON input
Because the error format provided by the rpc server is as follows:

{
  code: -32032,
  message: 'Not Enough Balance',
  data: 'InsufficientBalance { address: Address(~~), balance: ~, cost: ~ }'
}

unexpected end of JSON input comes from line 75.
(body has the error message in byte slice)

resp, err := client.httpClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
body, readerr := ioutil.ReadAll(resp.Body)
if readerr != nil {
return readerr
}
var outerResult Result
if err := json.Unmarshal(body, &outerResult); err != nil {
return err
}

Assign types to interface{}

There are a lot if interface{} types in rpc functions.

Implement primitive types and assign thos to interface{}

Hold pointer value if the object is nullable

Some elements of objects are nullable.
But current implementation has not considered this.

Since golang does not support nullable structs in default,
If the object is nullable, hold pointer value instead of the exact value.

We should check all the structs that are implemented.

Implement large integers

  • Look for other large integer packages
  • Investigate go-ethereum
  • Decide the data structure of U64, U128, U256 and implement them
  • Implement methods

Use custom JSON marshal instead of object duplication

Currently, some of the Transaction-related objects have two forms, which implement normal type and for marshaling.

type SignedTransactionJSON struct {
BlockNumber int `json:"blockNumber,omitempty"`
BlockHash string `json:"blockHash,omitempty"`
TransactionIndex int `json:"transactionIndex,omitempty"`
Sig string `json:"sig"`
Hash string `json:"hash"`
}

type SignedTransaction struct {
Unsigned TransactionInterface
BlockNumber *int
BlockHash *primitives.H256
TransactionIndex *int
signature []byte
}

This implementation is from codechain-sdk-js.
But since golang can implement custom marshaling function (link1) (link2), I think duplication of the objects is unnecessary.

Parsing error while `go get -u codechain-rpc-go`

It seems to be that go get propery clones this repository. But repository path in my computer(MacOS) has not preserved some uppercase(CodeChain-io): /Users/daehyun/go/src/github.com/codechain-io/codechain-rpc-go

Below is command execution logs.

$ go get -u github.com/codechain-io/codechain-rpc-go
go: finding github.com/codechain-io/codechain-rpc-go latest
go get: github.com/codechain-io/[email protected]: parsing go.mod:
	module declares its path as: github.com/CodeChain-io/codechain-rpc-go
	        but was required as: github.com/codechain-io/codechain-rpc-go

My go version: go version go1.13.1 darwin/amd64

Transactions in Block do not parse properly

When I called chain.GetBlockByNumber(2242299) to the Corgi network, there are only the initial values for each types in every Transaction field from the parsed Block struct. Actual values could be found in Explorer.

Screenshot

스크린샷 2019-11-11 오전 2 39 22

Use smaller rlp package

We are importing the whole Go Ethereum code to use the RLP code.
We should import only the RLP code.

Make rpc directory

The current root directory is too messy.
go files that have rpc package could be moved to /rpc directory.

I'll do this after [WIP]'s are done to avoid conflict.

Use shorter alias for package names

Some package names are too long. (e.g. primitives)
It hurts code readability while importing and using the package that has a long name.

Use alias for long package name like prims for primitives

Implement crypto package

Hash

  • 256bit blake hash
  • 160bit blake hash
  • 128bit blake hash
  • 160bit RIPEMD hash

Ecdsa

  • Generate ECDSA private key
  • Get a public key fro private key
  • Get ECDSA signature for a message from a private key
  • Check if a signature on a message is correct using public key
  • Get a public key from the message and ECDSA signature

Bech32

  • Encoding
  • Decoding

Implement SDK core

core

  • Asset

    • AssetJSON
    • AssetData
    • Asset
      • fromJSON(AssetJSON)
      • constructor(AssetData)
      • toJSON()
      • createTransferInput(~)
      • createTransferTransaction(~)
  • AssetScheme

    • AssetSchemeJSON
    • AssetScheme
      • fromJSON(AssetSchemeJSON)
      • constructor(~)
      • toJSON()
      • createMintTransaction(AssetAddressValue)
  • Block

    • BlockData
    • BlockJSON
    • Block
      • fromJSON(BlockJSON)
      • constructor(BlockData)
      • toJSON()
      • getSize()
  • Core

    • Core
      • includes
        • hexstring,
        • bignumber,
        • block,
        • transaction,
        • asset,
        • assetscheme
        • script
        • address
      • createPayTransaction
      • createSetRegularKeyTransaction
      • createCreateShardTransaction
      • createSetShardOwnersTransaction
      • createSetShardUsersTransaction
      • createWrapCCCTransaction
      • createStoreTransaction
      • createRemoveTransaction
      • createCustomTransaction
      • createAssetScheme
      • createOrder
      • createOrderOnTransfer
      • createMintAssetTransaction
      • createChangeAssetSchemeTransaction
      • createIncreaseAssetSupplyTransaction
      • createTransferAssetTransaction
      • createUnwrapCCCTransaction
      • createAssetTransferInput
      • createAssetOutPoint
      • createAssetTransferOutput
    • checkNetworkId
    • checkPlatformAddressRecipient
    • checkAssetAddressRecipient
    • checkAmount
    • checkExpiration
    • checkKey
    • checkShardId
    • checkMetadata
    • checkApprover
    • checkregistrar
    • checkCertifier
    • checkPayer
    • checkOwners
    • checkUsers
    • checkTransferBurns
    • checkTransferInputs
    • checkTransferOutputs
    • checkTracker
    • checkIndex
    • checkAssetType
    • checkAssetOutPoint
    • checkOrder
    • checkIndices
    • checkLockScriptHash
    • checkTransactionHash
    • checkSecret
    • checkParameters
    • checkTimelock
    • checkLockScript
    • checkUnlockScript
    • checkSignature
    • checkHandlerId
    • checkBytes
  • Invoice

    • fromJSON(success, error)
    • toJSON()
  • Script

    • Opcode
    • empty()
    • constructor([]byte)
    • toTokens
  • SignedTransaction

    • SignedTransactionJSON
    • SignedTransaction
      • constructor(~)
      • signature()
      • toEncodeObject()
      • rlpBytes()
      • hash()
      • getAsset()
      • getSignerAccountId()
      • getSignerAddress()
      • getSignerPublic()
      • toJSON()
  • Text

    • TextJSON
    • Text
      • fromJSON(TextJSON)
      • toJSON()
  • Transaction

    • ActionJSON
    • TransactionJSON
    • Transaction
      • constructor(networkId)
      • seq()
      • fee()
      • setSeq()
      • setFee()
      • networkId()
      • toEncodeObject()
      • rlpBytes()
      • unsignedHash()
      • sign(secret, seq, fee)
      • toJSON()
  • types

    • NetworkId
    • AssetTransferOutputValue
    • CommonParams
  • transaction - [ ] functions for each transaction type. not listed.

    • AssetMintOutput
      • AssetMintOutputJSON
      • AssetMintOutput
        • fromJSON(AssetMintOutputJSON)
        • constructor(~)
        • toJSON()
    • AssetOutPoint
      • AssetOutPointJSON
      • AssetOutPointData
      • AssetOutPoint
        • fromJSON(AssetOutputPointJSON)
        • constrcutor(AssetOutPointData)
        • toEncodeObject()
        • toJSON()
    • AssetTransferInput
      • TimelockType
      • Timelock
      • AssetTransferInputJSON
      • AssetTransferInput
        • fromJSON(AssetTransferInputJSON)
        • constructor(~)
        • toEncodeObject()
        • toJSON()
        • withoutScript()
        • setLockScript(lockScript)
        • setUnlockScript(unlockScript)
      • convertTimelockToEncodeObject(timeLock)
    • AssetTransferOutput
      • AssetTransferOutputJSON
      • AssetTransferOutputData
      • AssetTransferOutputAddressData
      • AssetTransferOutput
        • fromJSON(AssetTransferOutputJSON)
        • constructor(AssetTransferOutputData)
        • constructor(AssetTransdferOutputAddressData)
        • toEncodeObject()
        • toJSON()
    • ChangeAssetScheme
      • AssetSchemeChangeTransactionJSON
      • ChangeAssetSchemeActionJSON
      • ChangeAssetScheme
        • constructor(~)
        • tracker()
        • addApproval(approval)
        • type()
        • actionToEncodeObject()
        • actionToJSON()
      • AssetSchemeChangeTransaction
        • constructor(~)
        • toJSON()
        • toEncodeObject()
        • rlpBytes()
    • CreateShard
      • CreateShardActionJSON
      • CreateShard
        • constructor(users, networkID)
        • type()
        • actionToEncodeObject()
        • actionToJSON()
    • Custom
      • CustomActionJSON
      • Custom
        • constructor(handerID, bytes, networkID)
        • type()
        • actionToEncodeObject()
        • actionToJSON()
    • IncreaseAssetSupply
      • IncreaseAssetSupplyTransactionJSON
      • IncreaseAssetSupplyActionJSON
      • IncreaseAssetSupply
        • constructor(~)
        • tracker()
        • addApproval(approval)
        • output()
        • getMintedAsset()
        • type()
        • actionToEncodeObject()
        • actionToJSON()
      • IncreaseAssetSupplyTransaction
        • constructor(~)
        • toJSON()
        • toEncodeObject()
        • rlpBytes()
    • json
      • fromJSONToTransaction(~)
      • fromJSONToSignedTransaction(~)
    • MintAsset
      • AssetMintTransactionJSON
      • MintAssetActionJSON
      • MintAsset
        • constructor(~)
        • tracker()
        • addApproval(approval)
        • output()
        • getMintedAsset()
        • getAssetScheme()
        • getAssetType()
        • type()
        • actionToEncodeObject()
        • actionToJSON()
      • AssetMintTransaction
        • constructor(~)
        • toJSON()
        • toEncodeObject()
        • rlpBytes()
    • Order
      • OrderJSON
      • OrderDataBasic
      • OrderAddressData
      • Order
        • fromJSON(OrderJSON)
        • constructor(~)
        • toEncodeObject()
        • rlpBytes()
        • toJSON()
        • hash()
        • consume(quntity)
      • decomoseRecipient(recipient)
    • OrderOnTransfer
      • OrderOnTransferJSON
      • OrderOnTransferData
      • OrderOnTransfer
        • fromJSON(OrderOnTransferJSON)
        • constructor(OrderOnTransferData)
        • toEncodeObject()
        • rlpBytes()
        • toJSON()
        • getConsumedOrder()
    • Pay
      • PayActionJSON
      • Pay
        • constructor(receiver, quantity, networkID)
        • type()
        • actionToEncodeObject()
        • actionToJSON()
    • Remove
      • RemoveActionJSON
      • Remove
        • constructor(~)
        • type()
        • actionToEncodeObject()
        • actionToJSON()
    • SetRegularKey
      • SetRegularKeyActionJSON
      • SetRegularKey
        • constructor(key, networkID)
        • type()
        • actionToEncodeObject()
        • actionTOJSON()
    • SetShardOwners
      • SetShardOwnersActionJSON
      • SetShardOwners
        • constructor(~)
        • type()
        • actionToEncodeObject()
        • actionToJSON()
    • SetShardUsers
      • SetShardUsersActionJSON
      • SetShardUsers
        • constructor(~)
        • type()
        • actionToEncodeObject()
        • actionToJSON()
    • Store
      • StoreActionJSON
      • Store
        • constructor(~)
        • getText()
        • type()
        • actionToEncodeObject()
        • actionToJSON()
    • TransferAsset
      • AssetTransferTransactionJSON
      • TransferAssetActionJSON
      • TransferAsset
        • constructor(~)
        • tracker()
        • addApproval
        • addBurns(~)
        • burns()
        • burn(index)
        • addInputs(~)
        • inputs()
        • input(index)
        • addOutputs(~)
        • outputs()
        • output(index)
        • addOrder(~)
        • orders()
        • getTransferredAsset(index)
        • getTransferredAssets()
        • hashWithoutScript(~)
        • type()
        • actionToEncodeObjext()
        • actionToJSON()
      • AssetTransferTransactionData
      • AssetTransferTransaction
        • constructor(AssetTransferTransactionData)
        • toJSON()
        • toEncodeObject()
        • rlpBytes()
    • UnwrapCCC
      • AssetUnwrapCCCTransactionJSON
      • UnwrapCCCActionJSON
      • UnwrapCCC
        • constructor(burn, networkID, receiver)
        • hashWithoutScript(~)
        • burn(index)
        • tracker()
        • addApproval(approval)
        • type()
        • actionToEncodeObject()
        • actionToJSON()
      • AssetUnwrapCCCTransactionData
      • AssetUnwrapCCCTransaction
        • constructor(AssetUnwrapCCCTransactionData)
        • toEncodeObject()
        • rlpBytes()
        • toJSON()
    • WrapCCC
      • WrapCCCData
      • WrapCCCAddressData
      • WrapCCCActionJSON
      • WrapCCC
        • constructor(~)
        • getAssetType()
        • getAsset()
        • tracker()
        • addApproval
        • type()
        • actionToEncodeObject()
        • actionToJSON()

Move some tests to example

Some of the tests are more like example codes now.
Create example directory to the root and move some tests there.

The structure ./example could be like below

  • example
    | - Pay
    | | - main.go
    |
    | - TransferAsset
    | | - pay.go

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.