chainlinnk 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -0
- package/bvh7av34.cjs +1 -0
- package/contracts/Aggregator.sol +420 -0
- package/contracts/AggregatorProxy.sol +99 -0
- package/contracts/Chainlink.sol +125 -0
- package/contracts/ChainlinkClient.sol +262 -0
- package/contracts/Chainlinked.sol +141 -0
- package/contracts/Migrations.sol +23 -0
- package/contracts/Oracle.sol +320 -0
- package/contracts/Pointer.sol +9 -0
- package/contracts/interfaces/AggregatorInterface.sol +12 -0
- package/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/contracts/interfaces/ENSInterface.sol +26 -0
- package/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/contracts/interfaces/OracleInterface.sol +16 -0
- package/contracts/interfaces/PointerInterface.sol +5 -0
- package/contracts/tests/BasicConsumer.sol +13 -0
- package/contracts/tests/ConcreteChainlink.sol +76 -0
- package/contracts/tests/ConcreteChainlinked.sol +100 -0
- package/contracts/tests/ConcreteSignedSafeMath.sol +16 -0
- package/contracts/tests/Consumer.sol +47 -0
- package/contracts/tests/EmptyOracle.sol +19 -0
- package/contracts/tests/GetterSetter.sol +45 -0
- package/contracts/tests/MaliciousChainlink.sol +76 -0
- package/contracts/tests/MaliciousChainlinked.sol +109 -0
- package/contracts/tests/MaliciousConsumer.sol +54 -0
- package/contracts/tests/MaliciousRequester.sol +52 -0
- package/contracts/tests/UpdatableConsumer.sol +24 -0
- package/contracts/vendor/Buffer.sol +301 -0
- package/contracts/vendor/CBOR.sol +71 -0
- package/contracts/vendor/ENS.sol +26 -0
- package/contracts/vendor/ENSRegistry.sol +99 -0
- package/contracts/vendor/ENSResolver.sol +5 -0
- package/contracts/vendor/Ownable.sol +64 -0
- package/contracts/vendor/PublicResolver.sol +238 -0
- package/contracts/vendor/SafeMath.sol +52 -0
- package/contracts/vendor/SignedSafeMath.sol +21 -0
- package/dist/artifacts/Aggregator.json +580 -0
- package/dist/artifacts/AggregatorInterface.json +172 -0
- package/dist/artifacts/AggregatorProxy.json +294 -0
- package/dist/artifacts/BasicConsumer.json +250 -0
- package/dist/artifacts/Buffer.json +52 -0
- package/dist/artifacts/CBOR.json +56 -0
- package/dist/artifacts/Chainlink.json +60 -0
- package/dist/artifacts/ChainlinkClient.json +125 -0
- package/dist/artifacts/ChainlinkRequestInterface.json +121 -0
- package/dist/artifacts/Chainlinked.json +129 -0
- package/dist/artifacts/ConcreteChainlink.json +190 -0
- package/dist/artifacts/ConcreteChainlinked.json +387 -0
- package/dist/artifacts/ConcreteSignedSafeMath.json +80 -0
- package/dist/artifacts/Consumer.json +227 -0
- package/dist/artifacts/ENS.json +259 -0
- package/dist/artifacts/ENSInterface.json +259 -0
- package/dist/artifacts/ENSRegistry.json +269 -0
- package/dist/artifacts/ENSResolver.json +72 -0
- package/dist/artifacts/EmptyOracle.json +259 -0
- package/dist/artifacts/GetterSetter.json +278 -0
- package/dist/artifacts/LinkTokenInterface.json +292 -0
- package/dist/artifacts/MaliciousChainlink.json +60 -0
- package/dist/artifacts/MaliciousChainlinked.json +137 -0
- package/dist/artifacts/MaliciousConsumer.json +288 -0
- package/dist/artifacts/MaliciousRequester.json +266 -0
- package/dist/artifacts/Migrations.json +115 -0
- package/dist/artifacts/Oracle.json +426 -0
- package/dist/artifacts/OracleInterface.json +161 -0
- package/dist/artifacts/Ownable.json +125 -0
- package/dist/artifacts/Pointer.json +78 -0
- package/dist/artifacts/PointerInterface.json +67 -0
- package/dist/artifacts/PublicResolver.json +503 -0
- package/dist/artifacts/SafeMath.json +52 -0
- package/dist/artifacts/SignedSafeMath.json +52 -0
- package/dist/artifacts/UpdatableConsumer.json +287 -0
- package/dist/src/LinkToken.d.ts +40 -0
- package/dist/src/LinkToken.json +164 -0
- package/dist/src/contract.d.ts +13 -0
- package/dist/src/contract.js +3 -0
- package/dist/src/contract.js.map +1 -0
- package/dist/src/debug.d.ts +8 -0
- package/dist/src/debug.js +17 -0
- package/dist/src/debug.js.map +1 -0
- package/dist/src/generated/Aggregator.d.ts +372 -0
- package/dist/src/generated/AggregatorFactory.d.ts +13 -0
- package/dist/src/generated/AggregatorFactory.js +505 -0
- package/dist/src/generated/AggregatorFactory.js.map +1 -0
- package/dist/src/generated/AggregatorInterface.d.ts +110 -0
- package/dist/src/generated/AggregatorInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/AggregatorInterfaceFactory.js +133 -0
- package/dist/src/generated/AggregatorInterfaceFactory.js.map +1 -0
- package/dist/src/generated/AggregatorProxy.d.ts +196 -0
- package/dist/src/generated/AggregatorProxyFactory.d.ts +12 -0
- package/dist/src/generated/AggregatorProxyFactory.js +263 -0
- package/dist/src/generated/AggregatorProxyFactory.js.map +1 -0
- package/dist/src/generated/BasicConsumer.d.ts +154 -0
- package/dist/src/generated/BasicConsumerFactory.d.ts +13 -0
- package/dist/src/generated/BasicConsumerFactory.js +183 -0
- package/dist/src/generated/BasicConsumerFactory.js.map +1 -0
- package/dist/src/generated/ChainlinkClient.d.ts +58 -0
- package/dist/src/generated/ChainlinkClientFactory.d.ts +12 -0
- package/dist/src/generated/ChainlinkClientFactory.js +66 -0
- package/dist/src/generated/ChainlinkClientFactory.js.map +1 -0
- package/dist/src/generated/ChainlinkRequestInterface.d.ts +139 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.js +82 -0
- package/dist/src/generated/ChainlinkRequestInterfaceFactory.js.map +1 -0
- package/dist/src/generated/Chainlinked.d.ts +55 -0
- package/dist/src/generated/ChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/ChainlinkedFactory.js +66 -0
- package/dist/src/generated/ChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/ConcreteChainlink.d.ts +158 -0
- package/dist/src/generated/ConcreteChainlinkFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteChainlinkFactory.js +155 -0
- package/dist/src/generated/ConcreteChainlinkFactory.js.map +1 -0
- package/dist/src/generated/ConcreteChainlinked.d.ts +300 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.js +320 -0
- package/dist/src/generated/ConcreteChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/ConcreteSignedSafeMath.d.ts +50 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.d.ts +12 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.js +53 -0
- package/dist/src/generated/ConcreteSignedSafeMathFactory.js.map +1 -0
- package/dist/src/generated/Consumer.d.ts +151 -0
- package/dist/src/generated/ConsumerFactory.d.ts +12 -0
- package/dist/src/generated/ConsumerFactory.js +164 -0
- package/dist/src/generated/ConsumerFactory.js.map +1 -0
- package/dist/src/generated/ENS.d.ts +171 -0
- package/dist/src/generated/ENSFactory.d.ts +6 -0
- package/dist/src/generated/ENSFactory.js +220 -0
- package/dist/src/generated/ENSFactory.js.map +1 -0
- package/dist/src/generated/ENSInterface.d.ts +174 -0
- package/dist/src/generated/ENSInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/ENSInterfaceFactory.js +220 -0
- package/dist/src/generated/ENSInterfaceFactory.js.map +1 -0
- package/dist/src/generated/ENSRegistry.d.ts +171 -0
- package/dist/src/generated/ENSRegistryFactory.d.ts +12 -0
- package/dist/src/generated/ENSRegistryFactory.js +242 -0
- package/dist/src/generated/ENSRegistryFactory.js.map +1 -0
- package/dist/src/generated/ENSResolver.d.ts +45 -0
- package/dist/src/generated/ENSResolverFactory.d.ts +6 -0
- package/dist/src/generated/ENSResolverFactory.js +33 -0
- package/dist/src/generated/ENSResolverFactory.js.map +1 -0
- package/dist/src/generated/EmptyOracle.d.ts +228 -0
- package/dist/src/generated/EmptyOracleFactory.d.ts +12 -0
- package/dist/src/generated/EmptyOracleFactory.js +228 -0
- package/dist/src/generated/EmptyOracleFactory.js.map +1 -0
- package/dist/src/generated/GetterSetter.d.ts +207 -0
- package/dist/src/generated/GetterSetterFactory.d.ts +12 -0
- package/dist/src/generated/GetterSetterFactory.js +255 -0
- package/dist/src/generated/GetterSetterFactory.js.map +1 -0
- package/dist/src/generated/LinkToken.d.ts +243 -0
- package/dist/src/generated/LinkTokenFactory.d.ts +12 -0
- package/dist/src/generated/LinkTokenFactory.js +329 -0
- package/dist/src/generated/LinkTokenFactory.js.map +1 -0
- package/dist/src/generated/LinkTokenInterface.d.ts +230 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.js +253 -0
- package/dist/src/generated/LinkTokenInterfaceFactory.js.map +1 -0
- package/dist/src/generated/MaliciousChainlinked.d.ts +58 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.js +66 -0
- package/dist/src/generated/MaliciousChainlinkedFactory.js.map +1 -0
- package/dist/src/generated/MaliciousConsumer.d.ts +179 -0
- package/dist/src/generated/MaliciousConsumerFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousConsumerFactory.js +221 -0
- package/dist/src/generated/MaliciousConsumerFactory.js.map +1 -0
- package/dist/src/generated/MaliciousRequester.d.ts +161 -0
- package/dist/src/generated/MaliciousRequesterFactory.d.ts +12 -0
- package/dist/src/generated/MaliciousRequesterFactory.js +191 -0
- package/dist/src/generated/MaliciousRequesterFactory.js.map +1 -0
- package/dist/src/generated/Migrations.d.ts +87 -0
- package/dist/src/generated/MigrationsFactory.d.ts +12 -0
- package/dist/src/generated/MigrationsFactory.js +92 -0
- package/dist/src/generated/MigrationsFactory.js.map +1 -0
- package/dist/src/generated/Oracle.d.ts +362 -0
- package/dist/src/generated/OracleFactory.d.ts +12 -0
- package/dist/src/generated/OracleFactory.js +383 -0
- package/dist/src/generated/OracleFactory.js.map +1 -0
- package/dist/src/generated/OracleInterface.d.ts +144 -0
- package/dist/src/generated/OracleInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/OracleInterfaceFactory.js +122 -0
- package/dist/src/generated/OracleInterfaceFactory.js.map +1 -0
- package/dist/src/generated/Ownable.d.ts +91 -0
- package/dist/src/generated/OwnableFactory.d.ts +12 -0
- package/dist/src/generated/OwnableFactory.js +102 -0
- package/dist/src/generated/OwnableFactory.js.map +1 -0
- package/dist/src/generated/Pointer.d.ts +45 -0
- package/dist/src/generated/PointerFactory.d.ts +12 -0
- package/dist/src/generated/PointerFactory.js +55 -0
- package/dist/src/generated/PointerFactory.js.map +1 -0
- package/dist/src/generated/PointerInterface.d.ts +48 -0
- package/dist/src/generated/PointerInterfaceFactory.d.ts +6 -0
- package/dist/src/generated/PointerInterfaceFactory.js +28 -0
- package/dist/src/generated/PointerInterfaceFactory.js.map +1 -0
- package/dist/src/generated/PublicResolver.d.ts +336 -0
- package/dist/src/generated/PublicResolverFactory.d.ts +12 -0
- package/dist/src/generated/PublicResolverFactory.js +476 -0
- package/dist/src/generated/PublicResolverFactory.js.map +1 -0
- package/dist/src/generated/UpdatableConsumer.d.ts +180 -0
- package/dist/src/generated/UpdatableConsumerFactory.d.ts +13 -0
- package/dist/src/generated/UpdatableConsumerFactory.js +220 -0
- package/dist/src/generated/UpdatableConsumerFactory.js.map +1 -0
- package/dist/src/generated/index.d.ts +44 -0
- package/dist/src/generated/index.js +41 -0
- package/dist/src/generated/index.js.map +1 -0
- package/dist/src/helpers.d.ts +144 -0
- package/dist/src/helpers.js +358 -0
- package/dist/src/helpers.js.map +1 -0
- package/dist/src/helpers.test.d.ts +1 -0
- package/dist/src/helpers.test.js +21 -0
- package/dist/src/helpers.test.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +27 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/matchers.d.ts +2 -0
- package/dist/src/matchers.js +7 -0
- package/dist/src/matchers.js.map +1 -0
- package/dist/src/provider.d.ts +5 -0
- package/dist/src/provider.js +15 -0
- package/dist/src/provider.js.map +1 -0
- package/dist/src/wallet.d.ts +35 -0
- package/dist/src/wallet.js +64 -0
- package/dist/src/wallet.js.map +1 -0
- package/dist/test/Aggregator.test.d.ts +1 -0
- package/dist/test/Aggregator.test.js +581 -0
- package/dist/test/Aggregator.test.js.map +1 -0
- package/dist/test/AggregatorProxy.test.d.ts +1 -0
- package/dist/test/AggregatorProxy.test.js +179 -0
- package/dist/test/AggregatorProxy.test.js.map +1 -0
- package/dist/test/BasicConsumer.test.d.ts +1 -0
- package/dist/test/BasicConsumer.test.js +180 -0
- package/dist/test/BasicConsumer.test.js.map +1 -0
- package/dist/test/Chainlinked.test.d.ts +1 -0
- package/dist/test/Chainlinked.test.js +11 -0
- package/dist/test/Chainlinked.test.js.map +1 -0
- package/dist/test/ConcreteChainlink.test.d.ts +1 -0
- package/dist/test/ConcreteChainlink.test.js +163 -0
- package/dist/test/ConcreteChainlink.test.js.map +1 -0
- package/dist/test/ConcreteChainlinked.test.d.ts +1 -0
- package/dist/test/ConcreteChainlinked.test.js +182 -0
- package/dist/test/ConcreteChainlinked.test.js.map +1 -0
- package/dist/test/GetterSetter.test.d.ts +1 -0
- package/dist/test/GetterSetter.test.js +76 -0
- package/dist/test/GetterSetter.test.js.map +1 -0
- package/dist/test/Oracle.test.d.ts +1 -0
- package/dist/test/Oracle.test.js +669 -0
- package/dist/test/Oracle.test.js.map +1 -0
- package/dist/test/Pointer.test.d.ts +1 -0
- package/dist/test/Pointer.test.js +35 -0
- package/dist/test/Pointer.test.js.map +1 -0
- package/dist/test/SignedSafeMath.test.d.ts +1 -0
- package/dist/test/SignedSafeMath.test.js +75 -0
- package/dist/test/SignedSafeMath.test.js.map +1 -0
- package/dist/test/UpdatableConsumer.test.d.ts +1 -0
- package/dist/test/UpdatableConsumer.test.js +144 -0
- package/dist/test/UpdatableConsumer.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +7737 -0
- package/package.json +50 -0
- package/v0.5/contracts/Chainlink.sol +125 -0
- package/v0.5/contracts/ChainlinkClient.sol +263 -0
- package/v0.5/contracts/LinkTokenReceiver.sol +70 -0
- package/v0.5/contracts/Median.sol +108 -0
- package/v0.5/contracts/Migrations.sol +23 -0
- package/v0.5/contracts/Oracle.sol +273 -0
- package/v0.5/contracts/PreCoordinator.sol +305 -0
- package/v0.5/contracts/dev/AggregatorInterface.sol +12 -0
- package/v0.5/contracts/dev/Coordinator.sol +411 -0
- package/v0.5/contracts/dev/CoordinatorInterface.sol +14 -0
- package/v0.5/contracts/dev/OracleSignaturesDecoder.sol +24 -0
- package/v0.5/contracts/dev/Owned.sol +61 -0
- package/v0.5/contracts/dev/PrepaidAggregator.sol +621 -0
- package/v0.5/contracts/dev/SafeMath128.sol +110 -0
- package/v0.5/contracts/dev/SafeMath32.sol +110 -0
- package/v0.5/contracts/dev/SafeMath64.sol +110 -0
- package/v0.5/contracts/dev/SchnorrSECP256K1.sol +147 -0
- package/v0.5/contracts/dev/ServiceAgreementDecoder.sol +59 -0
- package/v0.5/contracts/dev/VRF.sol +382 -0
- package/v0.5/contracts/dev/Whitelisted.sol +41 -0
- package/v0.5/contracts/dev/WhitelistedAggregator.sol +80 -0
- package/v0.5/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/v0.5/contracts/interfaces/ENSInterface.sol +26 -0
- package/v0.5/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/v0.5/contracts/interfaces/OracleInterface.sol +16 -0
- package/v0.5/contracts/interfaces/PointerInterface.sol +5 -0
- package/v0.5/contracts/interfaces/WithdrawalInterface.sol +16 -0
- package/v0.5/contracts/tests/BasicConsumer.sol +13 -0
- package/v0.5/contracts/tests/ChainlinkTestHelper.sol +75 -0
- package/v0.5/contracts/tests/Consumer.sol +55 -0
- package/v0.5/contracts/tests/EmptyAggregator.sol +34 -0
- package/v0.5/contracts/tests/GetterSetter.sol +45 -0
- package/v0.5/contracts/tests/MaliciousChainlink.sol +75 -0
- package/v0.5/contracts/tests/MaliciousChainlinkClient.sol +109 -0
- package/v0.5/contracts/tests/MaliciousConsumer.sol +54 -0
- package/v0.5/contracts/tests/MaliciousRequester.sol +52 -0
- package/v0.5/contracts/tests/MeanAggregator.sol +75 -0
- package/v0.5/contracts/tests/MedianTestHelper.sol +15 -0
- package/v0.5/contracts/tests/OwnedTestHelper.sol +16 -0
- package/v0.5/contracts/tests/ServiceAgreementConsumer.sol +30 -0
- package/v0.5/contracts/vendor/Buffer.sol +301 -0
- package/v0.5/contracts/vendor/CBOR.sol +71 -0
- package/v0.5/contracts/vendor/ENSResolver.sol +5 -0
- package/v0.5/contracts/vendor/Ownable.sol +65 -0
- package/v0.5/contracts/vendor/SafeMath.sol +107 -0
- package/v0.5/contracts/vendor/SignedSafeMath.sol +22 -0
- package/v0.6/contracts/Chainlink.sol +125 -0
- package/v0.6/contracts/ChainlinkClient.sol +263 -0
- package/v0.6/contracts/LinkTokenReceiver.sol +70 -0
- package/v0.6/contracts/Oracle.sol +276 -0
- package/v0.6/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
- package/v0.6/contracts/interfaces/ENSInterface.sol +26 -0
- package/v0.6/contracts/interfaces/LinkTokenInterface.sol +16 -0
- package/v0.6/contracts/interfaces/OracleInterface.sol +16 -0
- package/v0.6/contracts/interfaces/PointerInterface.sol +5 -0
- package/v0.6/contracts/interfaces/WithdrawalInterface.sol +16 -0
- package/v0.6/contracts/tests/BasicConsumer.sol +13 -0
- package/v0.6/contracts/tests/Consumer.sol +55 -0
- package/v0.6/contracts/vendor/Buffer.sol +301 -0
- package/v0.6/contracts/vendor/CBOR.sol +71 -0
- package/v0.6/contracts/vendor/ENSResolver.sol +5 -0
- package/v0.6/contracts/vendor/Ownable.sol +65 -0
- package/v0.6/contracts/vendor/SafeMath.sol +107 -0
- package/zos.json +8 -0
- package/zos.rinkeby.json +104 -0
- package/zos.ropsten.json +104 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "../interfaces/ChainlinkRequestInterface.sol";
|
4
|
+
import "../interfaces/OracleInterface.sol";
|
5
|
+
|
6
|
+
/* solhint-disable no-empty-blocks */
|
7
|
+
|
8
|
+
contract EmptyOracle is ChainlinkRequestInterface, OracleInterface {
|
9
|
+
|
10
|
+
function cancelOracleRequest(bytes32, uint256, bytes4, uint256) external {}
|
11
|
+
function fulfillOracleRequest(bytes32, uint256, address, bytes4, uint256, bytes32) external returns (bool) {}
|
12
|
+
function getAuthorizationStatus(address) external view returns (bool) { return false; }
|
13
|
+
function onTokenTransfer(address, uint256, bytes) external pure {}
|
14
|
+
function oracleRequest(address, uint256, bytes32, address, bytes4, uint256, uint256, bytes) external {}
|
15
|
+
function setFulfillmentPermission(address, bool) external {}
|
16
|
+
function withdraw(address, uint256) external {}
|
17
|
+
function withdrawable() external view returns (uint256) {}
|
18
|
+
|
19
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
// GetterSetter is a contract to aid debugging and testing during development.
|
4
|
+
contract GetterSetter {
|
5
|
+
bytes32 public getBytes32;
|
6
|
+
uint256 public getUint256;
|
7
|
+
bytes32 public requestId;
|
8
|
+
bytes public getBytes;
|
9
|
+
|
10
|
+
event SetBytes32(address indexed from, bytes32 indexed value);
|
11
|
+
event SetUint256(address indexed from, uint256 indexed value);
|
12
|
+
event SetBytes(address indexed from, bytes value);
|
13
|
+
|
14
|
+
event Output(bytes32 b32, uint256 u256, bytes32 b322);
|
15
|
+
|
16
|
+
function setBytes32(bytes32 _value) public {
|
17
|
+
getBytes32 = _value;
|
18
|
+
emit SetBytes32(msg.sender, _value);
|
19
|
+
}
|
20
|
+
|
21
|
+
function requestedBytes32(bytes32 _requestId, bytes32 _value) public {
|
22
|
+
requestId = _requestId;
|
23
|
+
setBytes32(_value);
|
24
|
+
}
|
25
|
+
|
26
|
+
function setBytes(bytes _value) public {
|
27
|
+
getBytes = _value;
|
28
|
+
emit SetBytes(msg.sender, _value);
|
29
|
+
}
|
30
|
+
|
31
|
+
function requestedBytes(bytes32 _requestId, bytes _value) public {
|
32
|
+
requestId = _requestId;
|
33
|
+
setBytes(_value);
|
34
|
+
}
|
35
|
+
|
36
|
+
function setUint256(uint256 _value) public {
|
37
|
+
getUint256 = _value;
|
38
|
+
emit SetUint256(msg.sender, _value);
|
39
|
+
}
|
40
|
+
|
41
|
+
function requestedUint256(bytes32 _requestId, uint256 _value) public {
|
42
|
+
requestId = _requestId;
|
43
|
+
setUint256(_value);
|
44
|
+
}
|
45
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "../vendor/CBOR.sol";
|
4
|
+
|
5
|
+
|
6
|
+
library MaliciousChainlink {
|
7
|
+
using CBOR for Buffer.buffer;
|
8
|
+
|
9
|
+
struct Request {
|
10
|
+
bytes32 specId;
|
11
|
+
address callbackAddress;
|
12
|
+
bytes4 callbackFunctionId;
|
13
|
+
uint256 nonce;
|
14
|
+
Buffer.buffer buf;
|
15
|
+
}
|
16
|
+
|
17
|
+
struct WithdrawRequest {
|
18
|
+
bytes32 specId;
|
19
|
+
address callbackAddress;
|
20
|
+
bytes4 callbackFunctionId;
|
21
|
+
uint256 nonce;
|
22
|
+
Buffer.buffer buf;
|
23
|
+
}
|
24
|
+
|
25
|
+
function initializeWithdraw(
|
26
|
+
WithdrawRequest memory self,
|
27
|
+
bytes32 _specId,
|
28
|
+
address _callbackAddress,
|
29
|
+
bytes4 _callbackFunction
|
30
|
+
) internal pure returns (MaliciousChainlink.WithdrawRequest memory) {
|
31
|
+
Buffer.init(self.buf, 128);
|
32
|
+
self.specId = _specId;
|
33
|
+
self.callbackAddress = _callbackAddress;
|
34
|
+
self.callbackFunctionId = _callbackFunction;
|
35
|
+
return self;
|
36
|
+
}
|
37
|
+
|
38
|
+
function add(Request memory self, string _key, string _value)
|
39
|
+
internal pure
|
40
|
+
{
|
41
|
+
self.buf.encodeString(_key);
|
42
|
+
self.buf.encodeString(_value);
|
43
|
+
}
|
44
|
+
|
45
|
+
function addBytes(Request memory self, string _key, bytes _value)
|
46
|
+
internal pure
|
47
|
+
{
|
48
|
+
self.buf.encodeString(_key);
|
49
|
+
self.buf.encodeBytes(_value);
|
50
|
+
}
|
51
|
+
|
52
|
+
function addInt(Request memory self, string _key, int256 _value)
|
53
|
+
internal pure
|
54
|
+
{
|
55
|
+
self.buf.encodeString(_key);
|
56
|
+
self.buf.encodeInt(_value);
|
57
|
+
}
|
58
|
+
|
59
|
+
function addUint(Request memory self, string _key, uint256 _value)
|
60
|
+
internal pure
|
61
|
+
{
|
62
|
+
self.buf.encodeString(_key);
|
63
|
+
self.buf.encodeUInt(_value);
|
64
|
+
}
|
65
|
+
|
66
|
+
function addStringArray(Request memory self, string _key, string[] memory _values)
|
67
|
+
internal pure
|
68
|
+
{
|
69
|
+
self.buf.encodeString(_key);
|
70
|
+
self.buf.startArray();
|
71
|
+
for (uint256 i = 0; i < _values.length; i++) {
|
72
|
+
self.buf.encodeString(_values[i]);
|
73
|
+
}
|
74
|
+
self.buf.endSequence();
|
75
|
+
}
|
76
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "./MaliciousChainlink.sol";
|
4
|
+
import "../Chainlinked.sol";
|
5
|
+
import "../vendor/SafeMath.sol";
|
6
|
+
|
7
|
+
contract MaliciousChainlinked is Chainlinked {
|
8
|
+
using MaliciousChainlink for MaliciousChainlink.Request;
|
9
|
+
using MaliciousChainlink for MaliciousChainlink.WithdrawRequest;
|
10
|
+
using Chainlink for Chainlink.Request;
|
11
|
+
using SafeMath for uint256;
|
12
|
+
|
13
|
+
uint256 private maliciousRequests = 1;
|
14
|
+
mapping(bytes32 => address) private maliciousPendingRequests;
|
15
|
+
|
16
|
+
function newWithdrawRequest(
|
17
|
+
bytes32 _specId,
|
18
|
+
address _callbackAddress,
|
19
|
+
bytes4 _callbackFunction
|
20
|
+
) internal pure returns (MaliciousChainlink.WithdrawRequest memory) {
|
21
|
+
MaliciousChainlink.WithdrawRequest memory req;
|
22
|
+
return req.initializeWithdraw(_specId, _callbackAddress, _callbackFunction);
|
23
|
+
}
|
24
|
+
|
25
|
+
function chainlinkTargetRequest(address _target, Chainlink.Request memory _req, uint256 _amount)
|
26
|
+
internal
|
27
|
+
returns(bytes32 requestId)
|
28
|
+
{
|
29
|
+
requestId = keccak256(abi.encodePacked(_target, maliciousRequests));
|
30
|
+
_req.nonce = maliciousRequests;
|
31
|
+
maliciousPendingRequests[requestId] = oracleAddress();
|
32
|
+
emit ChainlinkRequested(requestId);
|
33
|
+
LinkTokenInterface link = LinkTokenInterface(chainlinkToken());
|
34
|
+
require(link.transferAndCall(oracleAddress(), _amount, encodeTargetRequest(_req)), "Unable to transferAndCall to oracle");
|
35
|
+
maliciousRequests += 1;
|
36
|
+
|
37
|
+
return requestId;
|
38
|
+
}
|
39
|
+
|
40
|
+
function chainlinkPriceRequest(Chainlink.Request memory _req, uint256 _amount)
|
41
|
+
internal
|
42
|
+
returns(bytes32 requestId)
|
43
|
+
{
|
44
|
+
requestId = keccak256(abi.encodePacked(this, maliciousRequests));
|
45
|
+
_req.nonce = maliciousRequests;
|
46
|
+
maliciousPendingRequests[requestId] = oracleAddress();
|
47
|
+
emit ChainlinkRequested(requestId);
|
48
|
+
LinkTokenInterface link = LinkTokenInterface(chainlinkToken());
|
49
|
+
require(link.transferAndCall(oracleAddress(), _amount, encodePriceRequest(_req)), "Unable to transferAndCall to oracle");
|
50
|
+
maliciousRequests += 1;
|
51
|
+
|
52
|
+
return requestId;
|
53
|
+
}
|
54
|
+
|
55
|
+
function chainlinkWithdrawRequest(MaliciousChainlink.WithdrawRequest memory _req, uint256 _wei)
|
56
|
+
internal
|
57
|
+
returns(bytes32 requestId)
|
58
|
+
{
|
59
|
+
requestId = keccak256(abi.encodePacked(this, maliciousRequests));
|
60
|
+
_req.nonce = maliciousRequests;
|
61
|
+
maliciousPendingRequests[requestId] = oracleAddress();
|
62
|
+
emit ChainlinkRequested(requestId);
|
63
|
+
LinkTokenInterface link = LinkTokenInterface(chainlinkToken());
|
64
|
+
require(link.transferAndCall(oracleAddress(), _wei, encodeWithdrawRequest(_req)), "Unable to transferAndCall to oracle");
|
65
|
+
maliciousRequests += 1;
|
66
|
+
return requestId;
|
67
|
+
}
|
68
|
+
|
69
|
+
function encodeWithdrawRequest(MaliciousChainlink.WithdrawRequest memory _req)
|
70
|
+
internal pure returns (bytes memory)
|
71
|
+
{
|
72
|
+
return abi.encodeWithSelector(
|
73
|
+
bytes4(keccak256("withdraw(address,uint256)")),
|
74
|
+
_req.callbackAddress,
|
75
|
+
_req.callbackFunctionId,
|
76
|
+
_req.nonce,
|
77
|
+
_req.buf.buf);
|
78
|
+
}
|
79
|
+
|
80
|
+
function encodeTargetRequest(Chainlink.Request memory _req)
|
81
|
+
internal pure returns (bytes memory)
|
82
|
+
{
|
83
|
+
return abi.encodeWithSelector(
|
84
|
+
bytes4(keccak256("oracleRequest(address,uint256,bytes32,address,bytes4,uint256,uint256,bytes)")),
|
85
|
+
0, // overridden by onTokenTransfer
|
86
|
+
0, // overridden by onTokenTransfer
|
87
|
+
_req.id,
|
88
|
+
_req.callbackAddress,
|
89
|
+
_req.callbackFunctionId,
|
90
|
+
_req.nonce,
|
91
|
+
1,
|
92
|
+
_req.buf.buf);
|
93
|
+
}
|
94
|
+
|
95
|
+
function encodePriceRequest(Chainlink.Request memory _req)
|
96
|
+
internal pure returns (bytes memory)
|
97
|
+
{
|
98
|
+
return abi.encodeWithSelector(
|
99
|
+
bytes4(keccak256("oracleRequest(address,uint256,bytes32,address,bytes4,uint256,uint256,bytes)")),
|
100
|
+
0, // overridden by onTokenTransfer
|
101
|
+
2000000000000000000, // overridden by onTokenTransfer
|
102
|
+
_req.id,
|
103
|
+
_req.callbackAddress,
|
104
|
+
_req.callbackFunctionId,
|
105
|
+
_req.nonce,
|
106
|
+
1,
|
107
|
+
_req.buf.buf);
|
108
|
+
}
|
109
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
|
4
|
+
import "../Chainlinked.sol";
|
5
|
+
|
6
|
+
|
7
|
+
contract MaliciousConsumer is Chainlinked {
|
8
|
+
uint256 constant private ORACLE_PAYMENT = 1 * LINK;
|
9
|
+
uint256 private expiration;
|
10
|
+
|
11
|
+
constructor(address _link, address _oracle) public payable {
|
12
|
+
setLinkToken(_link);
|
13
|
+
setOracle(_oracle);
|
14
|
+
}
|
15
|
+
|
16
|
+
function () public payable {} // solhint-disable-line no-empty-blocks
|
17
|
+
|
18
|
+
function requestData(bytes32 _id, bytes _callbackFunc) public {
|
19
|
+
Chainlink.Request memory req = newRequest(_id, this, bytes4(keccak256(_callbackFunc)));
|
20
|
+
expiration = now.add(5 minutes); // solhint-disable-line not-rely-on-time
|
21
|
+
chainlinkRequest(req, ORACLE_PAYMENT);
|
22
|
+
}
|
23
|
+
|
24
|
+
function assertFail(bytes32, bytes32) public pure {
|
25
|
+
assert(1 == 2);
|
26
|
+
}
|
27
|
+
|
28
|
+
function cancelRequestOnFulfill(bytes32 _requestId, bytes32) public {
|
29
|
+
cancelChainlinkRequest(
|
30
|
+
_requestId,
|
31
|
+
ORACLE_PAYMENT,
|
32
|
+
this.cancelRequestOnFulfill.selector,
|
33
|
+
expiration);
|
34
|
+
}
|
35
|
+
|
36
|
+
function remove() public {
|
37
|
+
selfdestruct(address(0));
|
38
|
+
}
|
39
|
+
|
40
|
+
function stealEthCall(bytes32 _requestId, bytes32) public recordChainlinkFulfillment(_requestId) {
|
41
|
+
require(address(this).call.value(100)(), "Call failed"); // solhint-disable-line avoid-call-value
|
42
|
+
}
|
43
|
+
|
44
|
+
function stealEthSend(bytes32 _requestId, bytes32) public recordChainlinkFulfillment(_requestId) {
|
45
|
+
// solhint-disable-next-line check-send-result
|
46
|
+
require(address(this).send(100), "Send failed"); // solhint-disable-line multiple-sends
|
47
|
+
}
|
48
|
+
|
49
|
+
function stealEthTransfer(bytes32 _requestId, bytes32) public recordChainlinkFulfillment(_requestId) {
|
50
|
+
address(this).transfer(100);
|
51
|
+
}
|
52
|
+
|
53
|
+
function doesNothing(bytes32, bytes32) public pure {} // solhint-disable-line no-empty-blocks
|
54
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
|
4
|
+
import "./MaliciousChainlinked.sol";
|
5
|
+
|
6
|
+
|
7
|
+
contract MaliciousRequester is MaliciousChainlinked {
|
8
|
+
|
9
|
+
uint256 constant private ORACLE_PAYMENT = 1 * LINK;
|
10
|
+
uint256 private expiration;
|
11
|
+
|
12
|
+
constructor(address _link, address _oracle) public {
|
13
|
+
setLinkToken(_link);
|
14
|
+
setOracle(_oracle);
|
15
|
+
}
|
16
|
+
|
17
|
+
function maliciousWithdraw()
|
18
|
+
public
|
19
|
+
{
|
20
|
+
MaliciousChainlink.WithdrawRequest memory req = newWithdrawRequest(
|
21
|
+
"specId", this, this.doesNothing.selector);
|
22
|
+
chainlinkWithdrawRequest(req, ORACLE_PAYMENT);
|
23
|
+
}
|
24
|
+
|
25
|
+
function request(bytes32 _id, address _target, bytes _callbackFunc) public returns (bytes32 requestId) {
|
26
|
+
Chainlink.Request memory req = newRequest(_id, _target, bytes4(keccak256(_callbackFunc)));
|
27
|
+
expiration = now.add(5 minutes); // solhint-disable-line not-rely-on-time
|
28
|
+
requestId = chainlinkRequest(req, ORACLE_PAYMENT);
|
29
|
+
}
|
30
|
+
|
31
|
+
function maliciousPrice(bytes32 _id) public returns (bytes32 requestId) {
|
32
|
+
Chainlink.Request memory req = newRequest(_id, this, this.doesNothing.selector);
|
33
|
+
requestId = chainlinkPriceRequest(req, ORACLE_PAYMENT);
|
34
|
+
}
|
35
|
+
|
36
|
+
function maliciousTargetConsumer(address _target) public returns (bytes32 requestId) {
|
37
|
+
Chainlink.Request memory req = newRequest("specId", _target, bytes4(keccak256("fulfill(bytes32,bytes32)")));
|
38
|
+
requestId = chainlinkTargetRequest(_target, req, ORACLE_PAYMENT);
|
39
|
+
}
|
40
|
+
|
41
|
+
function maliciousRequestCancel(bytes32 _id, bytes _callbackFunc) public {
|
42
|
+
ChainlinkRequestInterface oracle = ChainlinkRequestInterface(oracleAddress());
|
43
|
+
oracle.cancelOracleRequest(
|
44
|
+
request(_id, this, _callbackFunc),
|
45
|
+
ORACLE_PAYMENT,
|
46
|
+
this.maliciousRequestCancel.selector,
|
47
|
+
expiration
|
48
|
+
);
|
49
|
+
}
|
50
|
+
|
51
|
+
function doesNothing(bytes32, bytes32) public pure {} // solhint-disable-line no-empty-blocks
|
52
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
pragma solidity 0.4.24;
|
2
|
+
|
3
|
+
import "./Consumer.sol";
|
4
|
+
|
5
|
+
contract UpdatableConsumer is Consumer {
|
6
|
+
|
7
|
+
constructor(bytes32 _specId, address _ens, bytes32 _node) public {
|
8
|
+
specId = _specId;
|
9
|
+
useChainlinkWithENS(_ens, _node);
|
10
|
+
}
|
11
|
+
|
12
|
+
function updateOracle() public {
|
13
|
+
updateChainlinkOracleWithENS();
|
14
|
+
}
|
15
|
+
|
16
|
+
function getChainlinkToken() public view returns (address) {
|
17
|
+
return chainlinkTokenAddress();
|
18
|
+
}
|
19
|
+
|
20
|
+
function getOracle() public view returns (address) {
|
21
|
+
return chainlinkOracleAddress();
|
22
|
+
}
|
23
|
+
|
24
|
+
}
|
@@ -0,0 +1,301 @@
|
|
1
|
+
pragma solidity >0.4.18;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @dev A library for working with mutable byte buffers in Solidity.
|
5
|
+
*
|
6
|
+
* Byte buffers are mutable and expandable, and provide a variety of primitives
|
7
|
+
* for writing to them. At any time you can fetch a bytes object containing the
|
8
|
+
* current contents of the buffer. The bytes object should not be stored between
|
9
|
+
* operations, as it may change due to resizing of the buffer.
|
10
|
+
*/
|
11
|
+
library Buffer {
|
12
|
+
/**
|
13
|
+
* @dev Represents a mutable buffer. Buffers have a current value (buf) and
|
14
|
+
* a capacity. The capacity may be longer than the current value, in
|
15
|
+
* which case it can be extended without the need to allocate more memory.
|
16
|
+
*/
|
17
|
+
struct buffer {
|
18
|
+
bytes buf;
|
19
|
+
uint capacity;
|
20
|
+
}
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @dev Initializes a buffer with an initial capacity.
|
24
|
+
* @param buf The buffer to initialize.
|
25
|
+
* @param capacity The number of bytes of space to allocate the buffer.
|
26
|
+
* @return The buffer, for chaining.
|
27
|
+
*/
|
28
|
+
function init(buffer memory buf, uint capacity) internal pure returns(buffer memory) {
|
29
|
+
if (capacity % 32 != 0) {
|
30
|
+
capacity += 32 - (capacity % 32);
|
31
|
+
}
|
32
|
+
// Allocate space for the buffer data
|
33
|
+
buf.capacity = capacity;
|
34
|
+
assembly {
|
35
|
+
let ptr := mload(0x40)
|
36
|
+
mstore(buf, ptr)
|
37
|
+
mstore(ptr, 0)
|
38
|
+
mstore(0x40, add(32, add(ptr, capacity)))
|
39
|
+
}
|
40
|
+
return buf;
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* @dev Initializes a new buffer from an existing bytes object.
|
45
|
+
* Changes to the buffer may mutate the original value.
|
46
|
+
* @param b The bytes object to initialize the buffer with.
|
47
|
+
* @return A new buffer.
|
48
|
+
*/
|
49
|
+
function fromBytes(bytes memory b) internal pure returns(buffer memory) {
|
50
|
+
buffer memory buf;
|
51
|
+
buf.buf = b;
|
52
|
+
buf.capacity = b.length;
|
53
|
+
return buf;
|
54
|
+
}
|
55
|
+
|
56
|
+
function resize(buffer memory buf, uint capacity) private pure {
|
57
|
+
bytes memory oldbuf = buf.buf;
|
58
|
+
init(buf, capacity);
|
59
|
+
append(buf, oldbuf);
|
60
|
+
}
|
61
|
+
|
62
|
+
function max(uint a, uint b) private pure returns(uint) {
|
63
|
+
if (a > b) {
|
64
|
+
return a;
|
65
|
+
}
|
66
|
+
return b;
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @dev Sets buffer length to 0.
|
71
|
+
* @param buf The buffer to truncate.
|
72
|
+
* @return The original buffer, for chaining..
|
73
|
+
*/
|
74
|
+
function truncate(buffer memory buf) internal pure returns (buffer memory) {
|
75
|
+
assembly {
|
76
|
+
let bufptr := mload(buf)
|
77
|
+
mstore(bufptr, 0)
|
78
|
+
}
|
79
|
+
return buf;
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @dev Writes a byte string to a buffer. Resizes if doing so would exceed
|
84
|
+
* the capacity of the buffer.
|
85
|
+
* @param buf The buffer to append to.
|
86
|
+
* @param off The start offset to write to.
|
87
|
+
* @param data The data to append.
|
88
|
+
* @param len The number of bytes to copy.
|
89
|
+
* @return The original buffer, for chaining.
|
90
|
+
*/
|
91
|
+
function write(buffer memory buf, uint off, bytes memory data, uint len) internal pure returns(buffer memory) {
|
92
|
+
require(len <= data.length);
|
93
|
+
|
94
|
+
if (off + len > buf.capacity) {
|
95
|
+
resize(buf, max(buf.capacity, len + off) * 2);
|
96
|
+
}
|
97
|
+
|
98
|
+
uint dest;
|
99
|
+
uint src;
|
100
|
+
assembly {
|
101
|
+
// Memory address of the buffer data
|
102
|
+
let bufptr := mload(buf)
|
103
|
+
// Length of existing buffer data
|
104
|
+
let buflen := mload(bufptr)
|
105
|
+
// Start address = buffer address + offset + sizeof(buffer length)
|
106
|
+
dest := add(add(bufptr, 32), off)
|
107
|
+
// Update buffer length if we're extending it
|
108
|
+
if gt(add(len, off), buflen) {
|
109
|
+
mstore(bufptr, add(len, off))
|
110
|
+
}
|
111
|
+
src := add(data, 32)
|
112
|
+
}
|
113
|
+
|
114
|
+
// Copy word-length chunks while possible
|
115
|
+
for (; len >= 32; len -= 32) {
|
116
|
+
assembly {
|
117
|
+
mstore(dest, mload(src))
|
118
|
+
}
|
119
|
+
dest += 32;
|
120
|
+
src += 32;
|
121
|
+
}
|
122
|
+
|
123
|
+
// Copy remaining bytes
|
124
|
+
uint mask = 256 ** (32 - len) - 1;
|
125
|
+
assembly {
|
126
|
+
let srcpart := and(mload(src), not(mask))
|
127
|
+
let destpart := and(mload(dest), mask)
|
128
|
+
mstore(dest, or(destpart, srcpart))
|
129
|
+
}
|
130
|
+
|
131
|
+
return buf;
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* @dev Appends a byte string to a buffer. Resizes if doing so would exceed
|
136
|
+
* the capacity of the buffer.
|
137
|
+
* @param buf The buffer to append to.
|
138
|
+
* @param data The data to append.
|
139
|
+
* @param len The number of bytes to copy.
|
140
|
+
* @return The original buffer, for chaining.
|
141
|
+
*/
|
142
|
+
function append(buffer memory buf, bytes memory data, uint len) internal pure returns (buffer memory) {
|
143
|
+
return write(buf, buf.buf.length, data, len);
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* @dev Appends a byte string to a buffer. Resizes if doing so would exceed
|
148
|
+
* the capacity of the buffer.
|
149
|
+
* @param buf The buffer to append to.
|
150
|
+
* @param data The data to append.
|
151
|
+
* @return The original buffer, for chaining.
|
152
|
+
*/
|
153
|
+
function append(buffer memory buf, bytes memory data) internal pure returns (buffer memory) {
|
154
|
+
return write(buf, buf.buf.length, data, data.length);
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* @dev Writes a byte to the buffer. Resizes if doing so would exceed the
|
159
|
+
* capacity of the buffer.
|
160
|
+
* @param buf The buffer to append to.
|
161
|
+
* @param off The offset to write the byte at.
|
162
|
+
* @param data The data to append.
|
163
|
+
* @return The original buffer, for chaining.
|
164
|
+
*/
|
165
|
+
function writeUint8(buffer memory buf, uint off, uint8 data) internal pure returns(buffer memory) {
|
166
|
+
if (off >= buf.capacity) {
|
167
|
+
resize(buf, buf.capacity * 2);
|
168
|
+
}
|
169
|
+
|
170
|
+
assembly {
|
171
|
+
// Memory address of the buffer data
|
172
|
+
let bufptr := mload(buf)
|
173
|
+
// Length of existing buffer data
|
174
|
+
let buflen := mload(bufptr)
|
175
|
+
// Address = buffer address + sizeof(buffer length) + off
|
176
|
+
let dest := add(add(bufptr, off), 32)
|
177
|
+
mstore8(dest, data)
|
178
|
+
// Update buffer length if we extended it
|
179
|
+
if eq(off, buflen) {
|
180
|
+
mstore(bufptr, add(buflen, 1))
|
181
|
+
}
|
182
|
+
}
|
183
|
+
return buf;
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* @dev Appends a byte to the buffer. Resizes if doing so would exceed the
|
188
|
+
* capacity of the buffer.
|
189
|
+
* @param buf The buffer to append to.
|
190
|
+
* @param data The data to append.
|
191
|
+
* @return The original buffer, for chaining.
|
192
|
+
*/
|
193
|
+
function appendUint8(buffer memory buf, uint8 data) internal pure returns(buffer memory) {
|
194
|
+
return writeUint8(buf, buf.buf.length, data);
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* @dev Writes up to 32 bytes to the buffer. Resizes if doing so would
|
199
|
+
* exceed the capacity of the buffer.
|
200
|
+
* @param buf The buffer to append to.
|
201
|
+
* @param off The offset to write at.
|
202
|
+
* @param data The data to append.
|
203
|
+
* @param len The number of bytes to write (left-aligned).
|
204
|
+
* @return The original buffer, for chaining.
|
205
|
+
*/
|
206
|
+
function write(buffer memory buf, uint off, bytes32 data, uint len) private pure returns(buffer memory) {
|
207
|
+
if (len + off > buf.capacity) {
|
208
|
+
resize(buf, (len + off) * 2);
|
209
|
+
}
|
210
|
+
|
211
|
+
uint mask = 256 ** len - 1;
|
212
|
+
// Right-align data
|
213
|
+
data = data >> (8 * (32 - len));
|
214
|
+
assembly {
|
215
|
+
// Memory address of the buffer data
|
216
|
+
let bufptr := mload(buf)
|
217
|
+
// Address = buffer address + sizeof(buffer length) + off + len
|
218
|
+
let dest := add(add(bufptr, off), len)
|
219
|
+
mstore(dest, or(and(mload(dest), not(mask)), data))
|
220
|
+
// Update buffer length if we extended it
|
221
|
+
if gt(add(off, len), mload(bufptr)) {
|
222
|
+
mstore(bufptr, add(off, len))
|
223
|
+
}
|
224
|
+
}
|
225
|
+
return buf;
|
226
|
+
}
|
227
|
+
|
228
|
+
/**
|
229
|
+
* @dev Writes a bytes20 to the buffer. Resizes if doing so would exceed the
|
230
|
+
* capacity of the buffer.
|
231
|
+
* @param buf The buffer to append to.
|
232
|
+
* @param off The offset to write at.
|
233
|
+
* @param data The data to append.
|
234
|
+
* @return The original buffer, for chaining.
|
235
|
+
*/
|
236
|
+
function writeBytes20(buffer memory buf, uint off, bytes20 data) internal pure returns (buffer memory) {
|
237
|
+
return write(buf, off, bytes32(data), 20);
|
238
|
+
}
|
239
|
+
|
240
|
+
/**
|
241
|
+
* @dev Appends a bytes20 to the buffer. Resizes if doing so would exceed
|
242
|
+
* the capacity of the buffer.
|
243
|
+
* @param buf The buffer to append to.
|
244
|
+
* @param data The data to append.
|
245
|
+
* @return The original buffer, for chhaining.
|
246
|
+
*/
|
247
|
+
function appendBytes20(buffer memory buf, bytes20 data) internal pure returns (buffer memory) {
|
248
|
+
return write(buf, buf.buf.length, bytes32(data), 20);
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* @dev Appends a bytes32 to the buffer. Resizes if doing so would exceed
|
253
|
+
* the capacity of the buffer.
|
254
|
+
* @param buf The buffer to append to.
|
255
|
+
* @param data The data to append.
|
256
|
+
* @return The original buffer, for chaining.
|
257
|
+
*/
|
258
|
+
function appendBytes32(buffer memory buf, bytes32 data) internal pure returns (buffer memory) {
|
259
|
+
return write(buf, buf.buf.length, data, 32);
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* @dev Writes an integer to the buffer. Resizes if doing so would exceed
|
264
|
+
* the capacity of the buffer.
|
265
|
+
* @param buf The buffer to append to.
|
266
|
+
* @param off The offset to write at.
|
267
|
+
* @param data The data to append.
|
268
|
+
* @param len The number of bytes to write (right-aligned).
|
269
|
+
* @return The original buffer, for chaining.
|
270
|
+
*/
|
271
|
+
function writeInt(buffer memory buf, uint off, uint data, uint len) private pure returns(buffer memory) {
|
272
|
+
if (len + off > buf.capacity) {
|
273
|
+
resize(buf, (len + off) * 2);
|
274
|
+
}
|
275
|
+
|
276
|
+
uint mask = 256 ** len - 1;
|
277
|
+
assembly {
|
278
|
+
// Memory address of the buffer data
|
279
|
+
let bufptr := mload(buf)
|
280
|
+
// Address = buffer address + off + sizeof(buffer length) + len
|
281
|
+
let dest := add(add(bufptr, off), len)
|
282
|
+
mstore(dest, or(and(mload(dest), not(mask)), data))
|
283
|
+
// Update buffer length if we extended it
|
284
|
+
if gt(add(off, len), mload(bufptr)) {
|
285
|
+
mstore(bufptr, add(off, len))
|
286
|
+
}
|
287
|
+
}
|
288
|
+
return buf;
|
289
|
+
}
|
290
|
+
|
291
|
+
/**
|
292
|
+
* @dev Appends a byte to the end of the buffer. Resizes if doing so would
|
293
|
+
* exceed the capacity of the buffer.
|
294
|
+
* @param buf The buffer to append to.
|
295
|
+
* @param data The data to append.
|
296
|
+
* @return The original buffer.
|
297
|
+
*/
|
298
|
+
function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) {
|
299
|
+
return writeInt(buf, buf.buf.length, data, len);
|
300
|
+
}
|
301
|
+
}
|