-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from strategyobject/feature/abstract-hash
Revise rpc-api types
- Loading branch information
Showing
42 changed files
with
599 additions
and
190 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
6 changes: 6 additions & 0 deletions
6
common/src/main/java/com/strategyobject/substrateclient/common/types/Bytes.java
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,6 @@ | ||
package com.strategyobject.substrateclient.common.types; | ||
|
||
@FunctionalInterface | ||
public interface Bytes { | ||
byte[] getData(); | ||
} |
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
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
16 changes: 1 addition & 15 deletions
16
rpc/rpc-api/src/main/java/com/strategyobject/substrateclient/rpc/api/BlockHash.java
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 |
---|---|---|
@@ -1,18 +1,4 @@ | ||
package com.strategyobject.substrateclient.rpc.api; | ||
|
||
import com.strategyobject.substrateclient.common.types.FixedBytes; | ||
import com.strategyobject.substrateclient.common.types.Size; | ||
import com.strategyobject.substrateclient.scale.ScaleSelfWritable; | ||
import lombok.NonNull; | ||
|
||
public class BlockHash | ||
extends FixedBytes<Size.Of32> | ||
implements ScaleSelfWritable<BlockHash> { | ||
protected BlockHash(byte[] data) { | ||
super(data, Size.of32); | ||
} | ||
|
||
public static BlockHash fromBytes(byte @NonNull [] data) { | ||
return new BlockHash(data); | ||
} | ||
public interface BlockHash extends Hash { | ||
} |
21 changes: 0 additions & 21 deletions
21
rpc/rpc-api/src/main/java/com/strategyobject/substrateclient/rpc/api/BlockHashReader.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
rpc/rpc-api/src/main/java/com/strategyobject/substrateclient/rpc/api/BlockNumber.java
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,21 @@ | ||
package com.strategyobject.substrateclient.rpc.api; | ||
|
||
import com.strategyobject.substrateclient.scale.ScaleSelfWritable; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.math.BigInteger; | ||
|
||
@RequiredArgsConstructor(staticName = "of") | ||
@Getter | ||
@EqualsAndHashCode | ||
public class BlockNumber implements ScaleSelfWritable<BlockNumber> { | ||
public static final BlockNumber GENESIS = BlockNumber.of(BigInteger.ZERO); | ||
|
||
private final BigInteger value; | ||
|
||
public static BlockNumber of(long value) { | ||
return of(BigInteger.valueOf(value)); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
rpc/rpc-api/src/main/java/com/strategyobject/substrateclient/rpc/api/BlockNumberEncoder.java
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,14 @@ | ||
package com.strategyobject.substrateclient.rpc.api; | ||
|
||
import com.strategyobject.substrateclient.rpc.EncoderPair; | ||
import com.strategyobject.substrateclient.rpc.RpcEncoder; | ||
import com.strategyobject.substrateclient.rpc.annotation.AutoRegister; | ||
|
||
@AutoRegister(types = BlockNumber.class) | ||
public class BlockNumberEncoder implements RpcEncoder<BlockNumber> { | ||
|
||
@Override | ||
public Object encode(BlockNumber source, EncoderPair<?>... encoders) { | ||
return "0x" + source.getValue().toString(16); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...pc-api/src/main/java/com/strategyobject/substrateclient/rpc/api/BlockNumberU32Reader.java
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,24 @@ | ||
package com.strategyobject.substrateclient.rpc.api; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.strategyobject.substrateclient.scale.ScaleReader; | ||
import com.strategyobject.substrateclient.scale.ScaleType; | ||
import com.strategyobject.substrateclient.scale.annotation.AutoRegister; | ||
import com.strategyobject.substrateclient.scale.registries.ScaleReaderRegistry; | ||
import lombok.NonNull; | ||
import lombok.val; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
@AutoRegister(types = BlockNumber.class) | ||
public class BlockNumberU32Reader implements ScaleReader<BlockNumber> { | ||
@SuppressWarnings("unchecked") | ||
@Override | ||
public BlockNumber read(@NonNull InputStream stream, ScaleReader<?>... readers) throws IOException { | ||
Preconditions.checkArgument(readers == null || readers.length == 0); | ||
|
||
val u32Reader = (ScaleReader<Long>) ScaleReaderRegistry.getInstance().resolve(ScaleType.U32.class); | ||
return BlockNumber.of(u32Reader.read(stream)); | ||
} | ||
} |
Oops, something went wrong.