diff --git a/resources/contracts/wallet.data b/resources/contracts/wallet.data index f8664a4..427a415 100644 --- a/resources/contracts/wallet.data +++ b/resources/contracts/wallet.data @@ -1 +1 @@ -0x6060604052604051611166380380611166833981016040908152815160805160a0519190930180516001908101815533600160a060020a0316600381905560009081526101026020529384205592918190849084905b825181101560cc578281815181101560025760209081029091010151600160a060020a0316600282810161010081101560025701558251600282019061010290600090869085908110156002576020908102909101810151600160a060020a03168252810191909152604001600020556001016055565b50600055506101058190556201518042046101075550505050611073806100f36000396000f3606060405236156100da5760e060020a6000350463173825d9811461012c5780632f54bf6e146101805780634123cb6b146101a857806352375093146101b15780635c52c2f5146101bb578063659010e7146101e55780637065cb48146101ef578063746c91711461021c578063797af62714610225578063b20d30a914610238578063b61d27f614610265578063b75c7dc614610286578063ba51a6df146102b5578063c2cf7326146102e2578063c41a360a14610320578063cbf0b0c014610345578063f00d4b5d14610372578063f1736d86146103a4575b6103ae600034111561012a5760408051600160a060020a033316815234602082015281517fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c929181900390910190a15b565b6103ae60043560006000366040518083838082843782019150509250505060405180910390206103f3815b600160a060020a03331660009081526101026020526040812054818082811415610ce757610e51565b6103b06004355b600160a060020a03811660009081526101026020526040812054115b919050565b6103c460015481565b6103c46101075481565b6103ae60003660405180838380828437820191505092505050604051809103902061057281610157565b6103c46101065481565b6103ae60043560003660405180838380828437820191505092505050604051809103902061058181610157565b6103c460005481565b6103b06004355b60008161064781610157565b6103ae60043560003660405180838380828437820191505092505050604051809103902061089681610157565b6103c46004803590602480359160443591820191013560006108a233610187565b6103ae600435600160a060020a03331660009081526101026020526040812054908082811415610b0f57610b8e565b6103ae600435600036604051808383808284378201915050925050506040518091039020610b9481610157565b6103b0600435602435600082815261010360209081526040808320600160a060020a03851684526101029092528220548281811415610bec57610c01565b6103d660043560006002600183016101008110156100025750505060038101546101a3565b6103ae600435600036604051808383808284378201915050925050506040518091039020610c0a81610157565b6103ae6004356024356000600036604051808383808284378201915050925050506040518091039020610c1b81610157565b6103c46101055481565b005b604080519115158252519081900360200190f35b60408051918252519081900360200190f35b60408051600160a060020a03929092168252519081900360200190f35b1561045d57600160a060020a0383166000908152610102602052604081205492508214156104625761045d565b60408051600160a060020a038516815290517f58619076adf5bb0943d100ef88d52d7c3fd691b19d3a9071b555b651fbf418da9181900360200190a15b505050565b600160016000505403600060005054111561047c5761045d565b600060028361010081101561000257508301819055600160a060020a038416815261010260205260408120556105335b6101045460005b81811015610e59576101048054610108916000918490811015610002576000918252602080832090910154835282019290925260400181208054600160a060020a0319168155600181810183905560028281018054858255939493909281161561010002600019011604601f819010610ed157505b5050506001016104b3565b6104205b60015b60015481101561057e575b600154811080156105655750600281610100811015610002570154600014155b15610eef57600101610545565b1561057e576000610106555b50565b1561060e5761061282610187565b60018054810190819055600160a060020a038316906002906101008110156100025790900160005055600154600160a060020a03831660008181526101026020908152604091829020939093558051918252517f994a936646fe87ffe4f1e469d3d6aa417d6b855598397f323de5b449f765f0c3929181900390910190a15b5050565b1561061c5761060e565b6106246104ac565b60015460fa901061063757610637610537565b60015460fa901061058f5761060e565b156107595760008381526101086020526040812054600160a060020a03161461075957604060008190208054600182810154935160029384018054600160a060020a0394909416959490939192839285929181161561010002600019011604801561078a5780601f1061075f5761010080835404028352916020019161078a565b820191906000526020600020905b8154815290600101906020018083116106d657829003601f168201915b5050965050505050505060405180910390a16000838152610108602052604081208054600160a060020a0319168155600181810183905560028281018054858255939493909281161561010002600019011604601f81901061086457505b505050600191505b50919050565b820191906000526020600020905b81548152906001019060200180831161076d57829003601f168201915b505091505060006040518083038185876185025a03f1505050600084815261010860209081526040805192819020805460018281015433600160a060020a0381811689529688018c9052948701819052919094166060860181905260a06080870181815260029485018054978816156101000260001901909716949094049087018190527fe7c957c06e9a662c1a6c77366179f5b702b97651dc28eee7d5bf1dff6e40bb4a975093958a9592949193909160c0830190849080156106f35780601f106106c8576101008083540402835291602001916106f3565b601f01602090049060005260206000209081019061075191905b80821115610892576000815560010161087e565b5090565b1561060e575061010555565b15610ad7576108b6846000610fcc33610187565b15610975577f92ca3a80853e6663fa31fa10b99225f18d4902939b4c53a9caae9043f6efd00433858786866040518086600160a060020a0316815260200185815260200184600160a060020a031681526020018060200182810382528484828181526020019250808284378201915050965050505050505060405180910390a184600160a060020a03168484846040518083838082843782019150509250505060006040518083038185876185025a03f15060009350610ad792505050565b6000364360405180848480828437820191505082815260200193505050506040518091039020905080506109a88161022c565b1580156109cb575060008181526101086020526040812054600160a060020a0316145b15610ad75760008181526101086020908152604082208054600160a060020a0319168817815560018181018890556002918201805481865294849020909491821615610100026000190190911691909104601f908101929092048101918591908790839010610adf5760ff198135168380011785555b50610a4d92915061087e565b50507f1733cbb53659d713b79580f79f3f9ff215f78a7c7aa45890f3b89fc5cddfbf32813386888787604051808760001916815260200186600160a060020a0316815260200185815260200184600160a060020a03168152602001806020018281038252848482818152602001925080828437820191505097505050505050505060405180910390a15b949350505050565b82800160010185558215610a41579182015b82811115610a41578235826000505591602001919060010190610af1565b50506000828152610103602052604081206001810154600284900a929083161115610b8e5780546001828101805492909101835590839003905560408051600160a060020a03331681526020810186905281517fc7fb647e59b18047309aa15aad418e5d7ca96d173ad704f1031a2c3d7591734b929181900390910190a15b50505050565b1561060e57600154821115610ba85761060e565b6000829055610bb56104ac565b6040805183815290517facbdb084c721332ac59f9b8e392196c9eb0e4932862da8eb9beaf0dad4f550da9181900360200190a15050565b506001820154600282900a9081166000141593505b50505092915050565b1561060e5781600160a060020a0316ff5b15610b8e57610c2983610187565b15610c3357610b8e565b600160a060020a038416600090815261010260205260408120549250821415610c5b57610b8e565b610c636104ac565b600160a060020a03831660028361010081101561000257508301819055600160a060020a03851660008181526101026020908152604080832083905584835291829020869055815192835282019290925281517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c929181900390910190a150505050565b60008581526101036020526040812080549093501415610d81576000805483556001838101919091556101048054918201808255828015829011610d3e57818360005260206000209182019101610d3e919061087e565b505050600283018190556101048054879290811015610002576000919091527f4c0be60200faa20559308cb7b5a1bb3255c16cb1cab91f525b5ae7a03d02fabe01555b506001810154600283900a90811660001415610e515760408051600160a060020a03331681526020810187905281517fe1c52dc63b719ade82e8bea94cc41a0d5d28e4aaf536adb5e9cccc9ff8c1aeda929181900390910190a1815460019011610e3e57600085815261010360205261010480546040909220600201549091811015610002576040600090812092815260208082209092018190558781526101039091528082556001828101829055600292909201559350610e51565b8154600019018255600182018054821790555b505050919050565b61060e6101045460005b81811015611037576101048054829081101561000257600091825260208220015414610ec9576101048054610103916000918490811015610002576020600081812093815292909101548352820192909252604001812081815560018101829055600201555b600101610e63565b601f016020900490600052602060002090810190610528919061087e565b5b60018054118015610f1257506001546002906101008110156100025701546000145b15610f265760018054600019019055610ef0565b60015481108015610f495750600154600290610100811015610002570154600014155b8015610f6357506002816101008110156100025701546000145b15610fc757600154600290610100811015610002570154600282610100811015610002570155806101026000600283610100811015610002570154815260208101919091526040016000908120919091556001546002906101008110156100025701555b61053a565b156101a35761010754610fe25b62015180420490565b1115610ffb57600061010655610ff6610fd9565b610107555b61010654808301108015906110195750610106546101055490830111155b1561102f575061010680548201905560016101a3565b5060006101a3565b610104805460008083559190915261045d907f4c0be60200faa20559308cb7b5a1bb3255c16cb1cab91f525b5ae7a03d02fabe9081019061087e56 +0x6060604052604051611166380380611166833981016040908152815160805160a0519190930180516001908101815533600160a060020a0316600381905560009081526101026020529384205592918190849084905b825181101560cc578281815181101560025760209081029091010151600160a060020a0316600282810161010081101560025701558251600282019061010290600090869085908110156002576020908102909101810151600160a060020a03168252810191909152604001600020556001016055565b50600055506101058190556201518042046101075550505050611073806100f36000396000f3606060405236156100da5760e060020a6000350463173825d9811461012c5780632f54bf6e146101805780634123cb6b146101a857806352375093146101b15780635c52c2f5146101bb578063659010e7146101e55780637065cb48146101ef578063746c91711461021c578063797af62714610225578063b20d30a914610238578063b61d27f614610265578063b75c7dc614610286578063ba51a6df146102b5578063c2cf7326146102e2578063c41a360a14610320578063cbf0b0c014610345578063f00d4b5d14610372578063f1736d86146103a4575b6103ae600034111561012a5760408051600160a060020a033316815234602082015281517fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c929181900390910190a15b565b6103ae60043560006000366040518083838082843782019150509250505060405180910390206103f3815b600160a060020a03331660009081526101026020526040812054818082811415610ce757610e51565b6103b06004355b600160a060020a03811660009081526101026020526040812054115b919050565b6103c460015481565b6103c46101075481565b6103ae60003660405180838380828437820191505092505050604051809103902061057281610157565b6103c46101065481565b6103ae60043560003660405180838380828437820191505092505050604051809103902061058181610157565b6103c460005481565b6103b06004355b60008161064781610157565b6103ae60043560003660405180838380828437820191505092505050604051809103902061089681610157565b6103c46004803590602480359160443591820191013560006108a233610187565b6103ae600435600160a060020a03331660009081526101026020526040812054908082811415610b0f57610b8e565b6103ae600435600036604051808383808284378201915050925050506040518091039020610b9481610157565b6103b0600435602435600082815261010360209081526040808320600160a060020a03851684526101029092528220548281811415610bec57610c01565b6103d660043560006002600183016101008110156100025750505060038101546101a3565b6103ae600435600036604051808383808284378201915050925050506040518091039020610c0a81610157565b6103ae6004356024356000600036604051808383808284378201915050925050506040518091039020610c1b81610157565b6103c46101055481565b005b604080519115158252519081900360200190f35b60408051918252519081900360200190f35b60408051600160a060020a03929092168252519081900360200190f35b1561045d57600160a060020a0383166000908152610102602052604081205492508214156104625761045d565b60408051600160a060020a038516815290517f58619076adf5bb0943d100ef88d52d7c3fd691b19d3a9071b555b651fbf418da9181900360200190a15b505050565b600160016000505403600060005054111561047c5761045d565b600060028361010081101561000257508301819055600160a060020a038416815261010260205260408120556105335b6101045460005b81811015610e59576101048054610108916000918490811015610002576000918252602080832090910154835282019290925260400181208054600160a060020a0319168155600181810183905560028281018054858255939493909281161561010002600019011604601f819010610ed157505b5050506001016104b3565b6104205b60015b60015481101561057e575b600154811080156105655750600281610100811015610002570154600014155b15610eef57600101610545565b1561057e576000610106555b50565b1561060e5761061282610187565b60018054810190819055600160a060020a038316906002906101008110156100025790900160005055600154600160a060020a03831660008181526101026020908152604091829020939093558051918252517f994a936646fe87ffe4f1e469d3d6aa417d6b855598397f323de5b449f765f0c3929181900390910190a15b5050565b1561061c5761060e565b6106246104ac565b60015460fa901061063757610637610537565b60015460fa901061058f5761060e565b156107595760008381526101086020526040812054600160a060020a03161461075957604060008190208054600182810154935160029384018054600160a060020a0394909416959490939192839285929181161561010002600019011604801561078a5780601f1061075f5761010080835404028352916020019161078a565b820191906000526020600020905b8154815290600101906020018083116106d657829003601f168201915b5050965050505050505060405180910390a16000838152610108602052604081208054600160a060020a0319168155600181810183905560028281018054858255939493909281161561010002600019011604601f81901061086457505b505050600191505b50919050565b820191906000526020600020905b81548152906001019060200180831161076d57829003601f168201915b505091505060006040518083038185876185025a03f1505050600084815261010860209081526040805192819020805460018281015433600160a060020a0381811689529688018c9052948701819052919094166060860181905260a06080870181815260029485018054978816156101000260001901909716949094049087018190527fe7c957c06e9a662c1a6c77366179f5b702b97651dc28eee7d5bf1dff6e40bb4a975093958a9592949193909160c0830190849080156106f35780601f106106c8576101008083540402835291602001916106f3565b601f01602090049060005260206000209081019061075191905b80821115610892576000815560010161087e565b5090565b1561060e575061010555565b15610ad7576108b6846000610fcc33610187565b15610975577f92ca3a80853e6663fa31fa10b99225f18d4902939b4c53a9caae9043f6efd00433858786866040518086600160a060020a0316815260200185815260200184600160a060020a031681526020018060200182810382528484828181526020019250808284378201915050965050505050505060405180910390a184600160a060020a03168484846040518083838082843782019150509250505060006040518083038185876185025a03f15060009350610ad792505050565b6000364360405180848480828437820191505082815260200193505050506040518091039020905080506109a88161022c565b1580156109cb575060008181526101086020526040812054600160a060020a0316145b15610ad75760008181526101086020908152604082208054600160a060020a0319168817815560018181018890556002918201805481865294849020909491821615610100026000190190911691909104601f908101929092048101918591908790839010610adf5760ff198135168380011785555b50610a4d92915061087e565b50507f1733cbb53659d713b79580f79f3f9ff215f78a7c7aa45890f3b89fc5cddfbf32813386888787604051808760001916815260200186600160a060020a0316815260200185815260200184600160a060020a03168152602001806020018281038252848482818152602001925080828437820191505097505050505050505060405180910390a15b949350505050565b82800160010185558215610a41579182015b82811115610a41578235826000505591602001919060010190610af1565b50506000828152610103602052604081206001810154600284900a929083161115610b8e5780546001828101805492909101835590839003905560408051600160a060020a03331681526020810186905281517fc7fb647e59b18047309aa15aad418e5d7ca96d173ad704f1031a2c3d7591734b929181900390910190a15b50505050565b1561060e57600154821115610ba85761060e565b6000829055610bb56104ac565b6040805183815290517facbdb084c721332ac59f9b8e392196c9eb0e4932862da8eb9beaf0dad4f550da9181900360200190a15050565b506001820154600282900a9081166000141593505b50505092915050565b1561060e5781600160a060020a0316ff5b15610b8e57610c2983610187565b15610c3357610b8e565b600160a060020a038416600090815261010260205260408120549250821415610c5b57610b8e565b610c636104ac565b600160a060020a03831660028361010081101561000257508301819055600160a060020a03851660008181526101026020908152604080832083905584835291829020869055815192835282019290925281517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c929181900390910190a150505050565b60008581526101036020526040812080549093501415610d81576000805483556001838101919091556101048054918201808255828015829011610d3e57818360005260206000209182019101610d3e919061087e565b505050600283018190556101048054879290811015610002576000919091527f4c0be60200faa20559308cb7b5a1bb3255c16cb1cab91f525b5ae7a03d02fabe01555b506001810154600283900a90811660001415610e515760408051600160a060020a03331681526020810187905281517fe1c52dc63b719ade82e8bea94cc41a0d5d28e4aaf536adb5e9cccc9ff8c1aeda929181900390910190a1815460019011610e3e57600085815261010360205261010480546040909220600201549091811015610002576040600090812092815260208082209092018190558781526101039091528082556001828101829055600292909201559350610e51565b8154600019018255600182018054821790555b505050919050565b61060e6101045460005b81811015611037576101048054829081101561000257600091825260208220015414610ec9576101048054610103916000918490811015610002576020600081812093815292909101548352820192909252604001812081815560018101829055600201555b600101610e63565b601f016020900490600052602060002090810190610528919061087e565b5b60018054118015610f1257506001546002906101008110156100025701546000145b15610f265760018054600019019055610ef0565b60015481108015610f495750600154600290610100811015610002570154600014155b8015610f6357506002816101008110156100025701546000145b15610fc757600154600290610100811015610002570154600282610100811015610002570155806101026000600283610100811015610002570154815260208101919091526040016000908120919091556001546002906101008110156100025701555b61053a565b156101a35761010754610fe25b62015180420490565b1115610ffb57600061010655610ff6610fd9565b610107555b61010654808301108015906110195750610106546101055490830111155b1561102f575061010680548201905560016101a3565b5060006101a3565b610104805460008083559190915261045d907f4c0be60200faa20559308cb7b5a1bb3255c16cb1cab91f525b5ae7a03d02fabe9081019061087e56 \ No newline at end of file diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 0de20de..6b9aad9 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -141,7 +141,8 @@ SELECT issue_id, transaction_hash FROM issues -WHERE contract_address IS NULL; +WHERE contract_address IS NULL + AND issues.transaction_hash IS NOT NULL; -- Pull Requests ------------------------------------------------------------------- diff --git a/src/clj/commiteth/eth/core.clj b/src/clj/commiteth/eth/core.clj index a7c90e4..a543b38 100644 --- a/src/clj/commiteth/eth/core.clj +++ b/src/clj/commiteth/eth/core.clj @@ -24,6 +24,12 @@ (log/error "Method: " method ", error: " error)) (:result result))) +(defn estimate-gas + [from to value & [params]] + (eth-rpc "eth_estimateGas" [(merge params {:from from + :to to + :value value})])) + (defn hex->big-integer [hex] (new BigInteger (subs hex 2) 16)) @@ -50,10 +56,13 @@ (defn send-transaction [from to value & [params]] - (eth-rpc "personal_signAndSendTransaction" [(merge params {:from from - :to to - :value value}) - (eth-password)])) + ;; todo: estimate gas instead of hardcoding + (let [gas 1248650] + (eth-rpc "personal_signAndSendTransaction" [(merge params {:from from + :to to + :value value + :gas gas}) + (eth-password)]))) (defn get-transaction-receipt [hash] @@ -62,9 +71,7 @@ (defn deploy-contract [] (let [contract-code (-> "contracts/wallet.data" io/resource slurp)] - (send-transaction (eth-account) nil 1 - {:gas 1248650 - :data contract-code}))) + (send-transaction (eth-account) nil 1 {:data contract-code}))) (defn- format-param [param] diff --git a/src/clj/commiteth/github/core.clj b/src/clj/commiteth/github/core.clj index d894302..7bed7d7 100644 --- a/src/clj/commiteth/github/core.clj +++ b/src/clj/commiteth/github/core.clj @@ -120,13 +120,13 @@ (defn post-comment [user repo issue-number balance] (let [comment (generate-comment user repo issue-number balance)] - (log/debug "Posting comment to" (str user "/" repo) ":" comment) + (log/debug "Posting comment to" (str user "/" repo "/" issue-number) ":" comment) (issues/create-comment user repo issue-number comment (self-auth-params)))) (defn update-comment [user repo comment-id issue-number balance] (let [comment (generate-comment user repo issue-number balance)] - (log/debug (str "Updating " user "/" repo " comment #" comment-id " with contents: " comment)) + (log/debug (str "Updating " user "/" repo "/" issue-number " comment #" comment-id " with contents: " comment)) (issues/edit-comment user repo comment-id comment (self-auth-params)))) (defn get-issue diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index d09aa06..ed7d3ca 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -5,7 +5,7 @@ [commiteth.db.issues :as issues] [commiteth.db.users :as users] [commiteth.db.bounties :as bounties] - [overtone.at-at :refer [every mk-pool]] + [overtone.at-at :refer [every mk-pool stop-and-reset-pool!]] [clojure.tools.logging :as log] [mount.core :as mount])) @@ -15,8 +15,9 @@ "For each pending deployment: gets transasction receipt, updates db state, posts github comment and adds owners to the wallet" [] - (for [{issue-id :issue_id - transaction-hash :transaction_hash} (issues/list-pending-deployments)] + (doseq [{issue-id :issue_id + transaction-hash :transaction_hash} (issues/list-pending-deployments)] + (log/debug "pending deployment:" transaction-hash) (when-let [receipt (eth/get-transaction-receipt transaction-hash)] (log/info "transaction receipt for issue #" issue-id ": " receipt) (when-let [contract-address (:contractAddress receipt)] @@ -35,31 +36,34 @@ (defn self-sign-bounty "Walks through all issues eligible for bounty payout and signs corresponding transaction" [] - (for [{contract-address :contract_address - issue-id :issue_id - payout-address :payout_address} (bounties/pending-bounties-list)] - (let [value (eth/get-balance-hex contract-address)] - (->> - (wallet/execute contract-address payout-address value) - (bounties/update-confirm-hash issue-id))))) + (doseq [{contract-address :contract_address + issue-id :issue_id + payout-address :payout_address} (bounties/pending-bounties-list) + :let [value (eth/get-balance-hex contract-address)]] + (->> + (wallet/execute contract-address payout-address value) + (bounties/update-confirm-hash issue-id)))) (defn update-balance [] - (for [{contract-address :contract_address - login :login - repo :repo - comment-id :comment_id - issue-number :issue_number} (bounties/list-wallets)] + (doseq [{contract-address :contract_address + login :login + repo :repo + comment-id :comment_id + issue-number :issue_number} (bounties/list-wallets)] (when comment-id - (let [old-balance (issues/get-balance contract-address) + (let [{old-balance :balance} (issues/get-balance contract-address) current-balance-hex (eth/get-balance-hex contract-address) current-balance-eth (eth/hex->eth current-balance-hex 8)] (when-not (= old-balance current-balance-hex) (issues/update-balance contract-address current-balance-hex) (github/update-comment login repo comment-id issue-number current-balance-eth)))))) -(mount/defstate scheduler :start - (do - (every (* 5 60 1000) update-issue-contract-address pool) - (every (* 60 1000) self-sign-bounty pool) - (every (* 5 60 1000) update-balance pool))) +(mount/defstate scheduler + :start (do + (every (* 1 60 1000) update-issue-contract-address pool) + (every (* 1 60 1000) self-sign-bounty pool) + (every (* 1 60 1000) update-balance pool)) + :stop (do + (log/info "Stopping scheduler pool") + (stop-and-reset-pool! pool))) diff --git a/src/clj/commiteth/util/images.clj b/src/clj/commiteth/util/images.clj index b9434f7..e95ff9b 100644 --- a/src/clj/commiteth/util/images.clj +++ b/src/clj/commiteth/util/images.clj @@ -7,8 +7,7 @@ (defn ^BufferedImage create-image [width height] - (.. GraphicsEnvironment getLocalGraphicsEnvironment getDefaultScreenDevice getDefaultConfiguration - (createCompatibleImage width height))) + (new BufferedImage width height BufferedImage/TYPE_INT_ARGB)) (defn html->image [html width height]