Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
[Vechain] Increaase blockTime and add address checksum (#258)
Browse files Browse the repository at this point in the history
* Add blockTime to vechain

* Add address checksum

* Use utilz package
  • Loading branch information
vikmeup committed Aug 13, 2019
1 parent 11f56a9 commit 51273b9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
Binary file added cmd/api/run_api
Binary file not shown.
1 change: 1 addition & 0 deletions coins.yml
Expand Up @@ -110,6 +110,7 @@
handle: vechain
name: VeChain Token
decimals: 18
blockTime: 20000
sampleAddress: '0xB5e883349e68aB59307d1604555AC890fAC47128'

- id: 820
Expand Down
10 changes: 5 additions & 5 deletions platform/vechain/api.go
Expand Up @@ -46,7 +46,7 @@ func (p *Platform) GetBlockByNumber(num int64) (*blockatlas.Block, error) {

transactionsChan := p.getTransactions(block.Transactions)

var txs []blockatlas.Tx
txs := make([]blockatlas.Tx, 0)
for t := range transactionsChan {
txs = append(txs, NormalizeTransaction(t)...)
}
Expand Down Expand Up @@ -283,8 +283,8 @@ func NormalizeTransaction(t *NativeTransaction) (txs []blockatlas.Tx) {
value := blockatlas.Amount(valueBase10)
fromHex := t.Receipt.Outputs[outputIndex].Events[eventIndex].Topics[1]
toHex := t.Receipt.Outputs[outputIndex].Events[eventIndex].Topics[2]
from := formatHexToAddress(fromHex)
to := formatHexToAddress(toHex)
from := util.Checksum(formatHexToAddress(fromHex))
to := util.Checksum(formatHexToAddress(toHex))
block := t.Block

txs = append(txs, blockatlas.Tx{
Expand Down Expand Up @@ -330,8 +330,8 @@ func NormalizeTransaction(t *NativeTransaction) (txs []blockatlas.Tx) {
txs = append(txs, blockatlas.Tx{
ID: t.ID,
Coin: coin.VET,
From: transfer.Sender,
To: transfer.Recipient,
From: util.Checksum(transfer.Sender),
To: util.Checksum(transfer.Recipient),
Fee: fee,
Date: time,
Type: blockatlas.TxTransfer,
Expand Down
22 changes: 11 additions & 11 deletions platform/vechain/api_test.go
Expand Up @@ -12,7 +12,7 @@ const transferReceipt = `{
"block": 2620166,
"id": "0x2b8776bd4679fa2afa28b55d66d4f6c7c77522fc878ce294d25e32475b704517",
"nonce": "0x3657a2025b11f27f",
"origin": "0xb853d6a965fbc047aaa9f04d774d53861d7ed653",
"origin": "0xB853D6a965fBC047aaA9f04d774d53861d7eD653",
"timestamp": 1556569300,
"receipt": {
"paid": "0x1236efcbcbb340000",
Expand All @@ -24,7 +24,7 @@ const transferFailedReceipt = `{
"block": 2620166,
"id": "0x2b8776bd4679fa2afa28b55d66d4f6c7c77522fc878ce294d25e32475b704517",
"nonce": "0x3657a2025b11f27f",
"origin": "0xb853d6a965fbc047aaa9f04d774d53861d7ed653",
"origin": "0xB853D6a965fBC047aaA9f04d774d53861d7eD653",
"timestamp": 1556569300,
"receipt": {
"paid": "0x1236efcbcbb340000",
Expand All @@ -33,16 +33,16 @@ const transferFailedReceipt = `{
}`

const transferClause = `{
"to": "0xda623049a13df5c8a24f0d7713f4add4ab136b1f",
"to": "0xdA623049A13df5c8a24f0d7713F4adD4ab136B1f",
"value": "0x29bde5885d7ac80000"
}`

const tokenTransfer = `
{
"amount": "0x00000000000000000000000000000000000000000000000d8d726b7177a80000",
"block": 2620166,
"origin": "0xb853d6a965fbc047aaa9f04d774d53861d7ed653",
"receiver": "0x9f3742c2c2fe66c7fca08d77d2262c22e3d56ac8",
"origin": "0xB853D6a965fBC047aaA9f04d774d53861d7eD653",
"receiver": "0x9f3742C2c2fE66c7FCa08d77d2262C22e3D56ac8",
"timestamp": 1556569300,
"txId": "0x2b8776bd4679fa2afa28b55d66d4f6c7c77522fc878ce294d25e32475b704517"
}
Expand Down Expand Up @@ -121,8 +121,8 @@ const transaction = `
var expectedTransferTrx = blockatlas.Tx{
ID: "0x2b8776bd4679fa2afa28b55d66d4f6c7c77522fc878ce294d25e32475b704517",
Coin: coin.VET,
From: "0xb853d6a965fbc047aaa9f04d774d53861d7ed653",
To: "0xda623049a13df5c8a24f0d7713f4add4ab136b1f",
From: "0xB853D6a965fBC047aaA9f04d774d53861d7eD653",
To: "0xdA623049A13df5c8a24f0d7713F4adD4ab136B1f",
Fee: "21000000000000000000",
Date: 1556569300,
Type: "transfer",
Expand All @@ -137,8 +137,8 @@ var expectedTransferTrx = blockatlas.Tx{
var expectedVeThorTrx = blockatlas.Tx{
ID: "0x2b8776bd4679fa2afa28b55d66d4f6c7c77522fc878ce294d25e32475b704517",
Coin: coin.VET,
From: "0xb853d6a965fbc047aaa9f04d774d53861d7ed653",
To: "0x9f3742c2c2fe66c7fca08d77d2262c22e3d56ac8",
From: "0xB853D6a965fBC047aaA9f04d774d53861d7eD653",
To: "0x9f3742C2c2fE66c7FCa08d77d2262C22e3D56ac8",
Fee: "21000000000000000000",
Date: 1556569300,
Type: blockatlas.TxNativeTokenTransfer,
Expand All @@ -151,8 +151,8 @@ var expectedVeThorTrx = blockatlas.Tx{
TokenID: VeThorContract,
Decimals: 18,
Value: "250000000000000000000",
From: "0xb853d6a965fbc047aaa9f04d774d53861d7ed653",
To: "0x9f3742c2c2fe66c7fca08d77d2262c22e3d56ac8",
From: "0xB853D6a965fBC047aaA9f04d774d53861d7eD653",
To: "0x9f3742C2c2fE66c7FCa08d77d2262C22e3D56ac8",
},
}

Expand Down
37 changes: 37 additions & 0 deletions util/address.go
@@ -0,0 +1,37 @@
package util

import (
"golang.org/x/crypto/sha3"
"strings"
)

// Decode decodes a hex string with 0x prefix.
func Remove0x(input string) string {
if strings.HasPrefix(input, "0x") {
return input[2:]
}
return input
}

// Hex returns an EIP55-compliant hex string representation of the address.
func Checksum(unchecksummed string) string {
v := []byte(Remove0x(strings.ToLower(unchecksummed)))
sha := sha3.NewLegacyKeccak256()
sha.Write(v)
hash := sha.Sum(nil)

result := v
for i := 0; i < len(result); i++ {
hashByte := hash[i/2]
if i%2 == 0 {
hashByte = hashByte >> 4
} else {
hashByte &= 0xf
}
if result[i] > '9' && hashByte > 7 {
result[i] -= 32
}
}
val := string(result)
return "0x" + val
}

0 comments on commit 51273b9

Please sign in to comment.